@design.estate/dees-catalog 21.49.0 → 21.49.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/dist_bundle/bundle.js +85 -132
- package/dist_bundle/bundle.js.map +1 -1
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-QG5BHDQO.js → chunk-2O2L36Y3.js} +91 -69
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-QG5BHDQO.js.map → chunk-2O2L36Y3.js.map} +1 -1
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-Q5VY4AV7.js → chunk-DTFC5CU3.js} +493 -34
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/chunk-DTFC5CU3.js.map +1 -0
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-YOGT7PSU.js → dees-modal-4DMZSC7L.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-ORLONA36.js → dees-workspace-terminal-DM23WG2C.js} +3 -3
- package/dist_ts_web/00_commitinfo_data.js +1 -1
- package/dist_ts_web/elements/00group-appui/dees-appui-activitylog/dees-appui-activitylog.d.ts +2 -0
- package/dist_ts_web/elements/00group-appui/dees-appui-activitylog/dees-appui-activitylog.js +5 -20
- package/dist_ts_web/elements/00group-appui/dees-appui-mainmenu/dees-appui-mainmenu.d.ts +2 -0
- package/dist_ts_web/elements/00group-appui/dees-appui-mainmenu/dees-appui-mainmenu.js +5 -18
- package/dist_ts_web/elements/00group-appui/dees-appui-secondarymenu/dees-appui-secondarymenu.d.ts +2 -0
- package/dist_ts_web/elements/00group-appui/dees-appui-secondarymenu/dees-appui-secondarymenu.js +5 -18
- package/dist_ts_web/elements/00group-appui/dees-appui-tabs/dees-appui-tabs.d.ts +2 -0
- package/dist_ts_web/elements/00group-appui/dees-appui-tabs/dees-appui-tabs.js +10 -33
- package/dist_ts_web/elements/00group-feedback/dees-progressbar/dees-progressbar.d.ts +2 -0
- package/dist_ts_web/elements/00group-feedback/dees-progressbar/dees-progressbar.js +6 -14
- package/dist_ts_web/elements/00group-harness/dees-harness-message-list/dees-harness-message-list.d.ts +2 -0
- package/dist_ts_web/elements/00group-harness/dees-harness-message-list/dees-harness-message-list.js +14 -4
- package/dist_ts_web/elements/00group-input/dees-input-dropdown/dees-input-dropdown-popup.d.ts +2 -0
- package/dist_ts_web/elements/00group-input/dees-input-dropdown/dees-input-dropdown-popup.js +5 -18
- package/dist_ts_web/elements/00group-input/dees-input-tags/dees-input-tags.d.ts +2 -0
- package/dist_ts_web/elements/00group-input/dees-input-tags/dees-input-tags.js +14 -23
- package/dist_ts_web/elements/00group-input/dees-input-wysiwyg/blocks/text/code.block.js +7 -19
- package/dist_ts_web/elements/00group-input/dees-input-wysiwyg/wysiwyg.markdown.view.d.ts +3 -0
- package/dist_ts_web/elements/00group-input/dees-input-wysiwyg/wysiwyg.markdown.view.js +15 -1
- package/dist_ts_web/elements/00scrollbars.d.ts +122 -0
- package/dist_ts_web/elements/00scrollbars.js +545 -0
- package/dist_ts_web/elements/00scrolledges.d.ts +1 -14
- package/dist_ts_web/elements/00scrolledges.js +7 -70
- package/dist_ts_web/elements/00scrollerwatch.d.ts +31 -0
- package/dist_ts_web/elements/00scrollerwatch.js +88 -0
- package/dist_ts_web/elements/index.d.ts +1 -0
- package/dist_ts_web/elements/index.js +3 -1
- package/package.json +1 -1
- package/readme.md +45 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/elements/00group-appui/dees-appui-activitylog/dees-appui-activitylog.ts +8 -19
- package/ts_web/elements/00group-appui/dees-appui-mainmenu/dees-appui-mainmenu.ts +8 -17
- package/ts_web/elements/00group-appui/dees-appui-secondarymenu/dees-appui-secondarymenu.ts +8 -17
- package/ts_web/elements/00group-appui/dees-appui-tabs/dees-appui-tabs.ts +13 -32
- package/ts_web/elements/00group-feedback/dees-progressbar/dees-progressbar.ts +9 -13
- package/ts_web/elements/00group-harness/dees-harness-message-list/dees-harness-message-list.ts +13 -3
- package/ts_web/elements/00group-input/dees-input-dropdown/dees-input-dropdown-popup.ts +8 -17
- package/ts_web/elements/00group-input/dees-input-tags/dees-input-tags.ts +17 -22
- package/ts_web/elements/00group-input/dees-input-wysiwyg/blocks/text/code.block.ts +7 -18
- package/ts_web/elements/00group-input/dees-input-wysiwyg/wysiwyg.markdown.view.ts +14 -0
- package/ts_web/elements/00scrollbars.ts +613 -0
- package/ts_web/elements/00scrolledges.ts +6 -71
- package/ts_web/elements/00scrollerwatch.ts +89 -0
- package/ts_web/elements/index.ts +2 -0
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/chunk-Q5VY4AV7.js.map +0 -1
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-YOGT7PSU.js.map → dees-modal-4DMZSC7L.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-ORLONA36.js.map → dees-workspace-terminal-DM23WG2C.js.map} +0 -0
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
import { css, type CSSResult, type DeesElement } from '@design.estate/dees-element';
|
|
2
|
+
import type { TReactiveController } from './00controller.js';
|
|
3
|
+
import { ScrollerWatch } from './00scrollerwatch.js';
|
|
4
|
+
|
|
5
|
+
/** How long a rail stays shown after the scroller last scrolled along it. */
|
|
6
|
+
const scrollingHoldMs = 1000;
|
|
7
|
+
/** A rail's breadth: the band along the scroller's edge its thumb is drawn in and grabbed by. */
|
|
8
|
+
const railBreadthPx = 10;
|
|
9
|
+
/** The gap a thumb keeps to either end of its rail. */
|
|
10
|
+
const railEndInsetPx = 2;
|
|
11
|
+
/** The shortest thumb, so the thumb of a long scroller stays easy to grab. */
|
|
12
|
+
const minThumbPx = 24;
|
|
13
|
+
/** Overflow within this distance is layout rounding, not content to scroll to. */
|
|
14
|
+
const overflowThresholdPx = 1;
|
|
15
|
+
|
|
16
|
+
/** What the window sees of a drag whose scroller left the document while the thumb was held. */
|
|
17
|
+
const orphanedDragEnds = ['pointerup', 'pointercancel', 'pointerdown'] as const;
|
|
18
|
+
|
|
19
|
+
/** The attribute a scroller with overlay scrollbars carries; it hides the scroller's native scrollbars. */
|
|
20
|
+
const scrollerAttribute = 'data-overlay-scrollbars';
|
|
21
|
+
/** Carried by the scroller while the pointer rests on a thumb, for the arrow cursor. */
|
|
22
|
+
const grabAttribute = 'data-overlay-scrollbars-grab';
|
|
23
|
+
/** Carried by the scroller while a thumb is dragged, so the drag selects no text. */
|
|
24
|
+
const dragAttribute = 'data-overlay-scrollbars-drag';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The scrollbars of a scroller with overlay scrollbars: rails along its end and bottom edges that
|
|
28
|
+
* take no room and no pointer input, each with a thumb of `--dees-color-scrollbar-thumb` that turns
|
|
29
|
+
* `--dees-color-scrollbar-thumb-hover` while the pointer rests on it or drags it. A rail is
|
|
30
|
+
* invisible until the scroller scrolls along it, and stays shown for a second after the last
|
|
31
|
+
* scroll; on a device with hover it also shows while the pointer is over the scroller, so a mouse
|
|
32
|
+
* finds it and drags it. It fades in with the theme's fast step and out with its slow one, at once
|
|
33
|
+
* under reduced motion. The scroller's native scrollbars are hidden, on every platform, so a
|
|
34
|
+
* classic scrollbar takes no gutter either; in forced colours the native scrollbars come back and
|
|
35
|
+
* the rails go.
|
|
36
|
+
*
|
|
37
|
+
* A host renders the scroller inside a box with `position: relative`, the box the rails are placed
|
|
38
|
+
* in; `OverlayScrollbarController` (or `OverlayScrollbars` outside Lit) inserts them right after
|
|
39
|
+
* the scroller.
|
|
40
|
+
*/
|
|
41
|
+
export const overlayScrollbarStyles: CSSResult = css`
|
|
42
|
+
@media (forced-colors: none) {
|
|
43
|
+
[data-overlay-scrollbars] {
|
|
44
|
+
scrollbar-width: none;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
[data-overlay-scrollbars]::-webkit-scrollbar {
|
|
48
|
+
display: none;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
[data-overlay-scrollbars][data-overlay-scrollbars-grab],
|
|
53
|
+
[data-overlay-scrollbars][data-overlay-scrollbars-grab] * {
|
|
54
|
+
cursor: default !important;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
[data-overlay-scrollbars][data-overlay-scrollbars-drag],
|
|
58
|
+
[data-overlay-scrollbars][data-overlay-scrollbars-drag] * {
|
|
59
|
+
-webkit-user-select: none;
|
|
60
|
+
user-select: none;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.overlayScrollbar {
|
|
64
|
+
position: absolute;
|
|
65
|
+
z-index: 2;
|
|
66
|
+
box-sizing: border-box;
|
|
67
|
+
opacity: 0;
|
|
68
|
+
pointer-events: none;
|
|
69
|
+
transition: opacity var(--dees-transition-slow) var(--dees-ease-standard);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.overlayScrollbar[hidden] {
|
|
73
|
+
display: none;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.overlayScrollbar[data-scrolling],
|
|
77
|
+
.overlayScrollbar[data-hovered],
|
|
78
|
+
.overlayScrollbar[data-dragging] {
|
|
79
|
+
opacity: 1;
|
|
80
|
+
transition-duration: var(--dees-transition-fast);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@media (hover: hover) {
|
|
84
|
+
[data-overlay-scrollbars]:hover + .overlayScrollbar,
|
|
85
|
+
[data-overlay-scrollbars]:hover + .overlayScrollbar + .overlayScrollbar {
|
|
86
|
+
opacity: 1;
|
|
87
|
+
transition-duration: var(--dees-transition-fast);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.overlayScrollbarThumb {
|
|
92
|
+
position: absolute;
|
|
93
|
+
top: 0;
|
|
94
|
+
left: 0;
|
|
95
|
+
border-radius: var(--dees-radius-full);
|
|
96
|
+
background: var(--dees-color-scrollbar-thumb);
|
|
97
|
+
transition: background-color var(--dees-transition-fast) var(--dees-ease-standard);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.overlayScrollbarY .overlayScrollbarThumb {
|
|
101
|
+
right: 0;
|
|
102
|
+
width: 6px;
|
|
103
|
+
margin-inline: auto;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.overlayScrollbarX .overlayScrollbarThumb {
|
|
107
|
+
bottom: 0;
|
|
108
|
+
height: 6px;
|
|
109
|
+
margin-block: auto;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.overlayScrollbar[data-hovered] .overlayScrollbarThumb,
|
|
113
|
+
.overlayScrollbar[data-dragging] .overlayScrollbarThumb {
|
|
114
|
+
background: var(--dees-color-scrollbar-thumb-hover);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@media (forced-colors: active) {
|
|
118
|
+
.overlayScrollbar {
|
|
119
|
+
display: none;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@media (prefers-reduced-motion: reduce) {
|
|
124
|
+
.overlayScrollbar,
|
|
125
|
+
.overlayScrollbarThumb {
|
|
126
|
+
transition: none;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
|
|
131
|
+
export interface IOverlayScrollbarsOptions {
|
|
132
|
+
/** Told when the pointer starts dragging a thumb (`true`) and when it lets go (`false`). */
|
|
133
|
+
onDrag?: (dragging: boolean) => void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** One axis's rail and thumb, and what was last measured of it. */
|
|
137
|
+
interface IOverlayAxis {
|
|
138
|
+
readonly vertical: boolean;
|
|
139
|
+
readonly rail: HTMLDivElement;
|
|
140
|
+
readonly thumb: HTMLDivElement;
|
|
141
|
+
/** Whether the scroller scrolls along this axis and has content past its edge, so the rail is placed. */
|
|
142
|
+
shown: boolean;
|
|
143
|
+
/** The length the thumb travels in: the rail's length less both end insets. */
|
|
144
|
+
track: number;
|
|
145
|
+
/** The thumb's length as last placed. */
|
|
146
|
+
length: number;
|
|
147
|
+
/** The scroll offset along the axis as last seen, to tell which axis a scroll moved. */
|
|
148
|
+
offset: number;
|
|
149
|
+
scrollingTimer: ReturnType<typeof setTimeout> | undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
interface IOverlayDrag {
|
|
153
|
+
readonly axis: IOverlayAxis;
|
|
154
|
+
readonly pointerId: number;
|
|
155
|
+
readonly startPointer: number;
|
|
156
|
+
readonly startScroll: number;
|
|
157
|
+
/** Scroll distance per pixel of thumb travel. */
|
|
158
|
+
readonly ratio: number;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const createAxis = (vertical: boolean): IOverlayAxis => {
|
|
162
|
+
const rail = document.createElement('div');
|
|
163
|
+
rail.className = `overlayScrollbar ${vertical ? 'overlayScrollbarY' : 'overlayScrollbarX'}`;
|
|
164
|
+
rail.setAttribute('aria-hidden', 'true');
|
|
165
|
+
rail.hidden = true;
|
|
166
|
+
const thumb = document.createElement('div');
|
|
167
|
+
thumb.className = 'overlayScrollbarThumb';
|
|
168
|
+
rail.append(thumb);
|
|
169
|
+
return { vertical, rail, thumb, shown: false, track: 0, length: 0, offset: 0, scrollingTimer: undefined };
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const scrollsAlong = (overflow: string): boolean => overflow === 'auto' || overflow === 'scroll';
|
|
173
|
+
|
|
174
|
+
const setStyle = (element: HTMLElement, property: 'left' | 'top' | 'width' | 'height' | 'transform', value: string): void => {
|
|
175
|
+
if (element.style[property] !== value) {
|
|
176
|
+
element.style[property] = value;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Overlay scrollbars for one scroller, without Lit: the rails `overlayScrollbarStyles` draws,
|
|
182
|
+
* inserted right after the scroller, placed over its padding box and kept in step with where it
|
|
183
|
+
* is scrolled to. The scroller carries `data-overlay-scrollbars` while attached, which hides its
|
|
184
|
+
* native scrollbars.
|
|
185
|
+
*
|
|
186
|
+
* The rails take no pointer input: wheel, touch, keyboard and clicks all stay the scroller's own.
|
|
187
|
+
* A mouse or pen press on a shown thumb is the one exception: it is taken from the content
|
|
188
|
+
* beneath, drags the thumb and scrolls the scroller with it, and the click that ends it reaches
|
|
189
|
+
* nothing. A press on the rail beside the thumb reaches the content.
|
|
190
|
+
*
|
|
191
|
+
* It follows its scroller as `ScrollEdgeShadowController` does: it measures when the scroller
|
|
192
|
+
* scrolls, resizes, or its children resize, come or go. A host that changes the scroller in a way
|
|
193
|
+
* none of these see calls `sync()`.
|
|
194
|
+
*
|
|
195
|
+
* Outside a drag it holds nothing beyond the scroller, so a scroller dropped with the DOM around it
|
|
196
|
+
* needs no `detach()`; a drag whose scroller leaves the document ends at the next release or press.
|
|
197
|
+
*/
|
|
198
|
+
export class OverlayScrollbars {
|
|
199
|
+
private readonly watch = new ScrollerWatch(() => this.handleScroll(), () => this.invalidate());
|
|
200
|
+
private readonly y = createAxis(true);
|
|
201
|
+
private readonly x = createAxis(false);
|
|
202
|
+
private rtl = false;
|
|
203
|
+
private frame = 0;
|
|
204
|
+
private drag: IOverlayDrag | null = null;
|
|
205
|
+
private suppressingClick = false;
|
|
206
|
+
|
|
207
|
+
constructor(private readonly options: IOverlayScrollbarsOptions = {}) {}
|
|
208
|
+
|
|
209
|
+
/** The scroller attached now, if any. */
|
|
210
|
+
public get scroller(): HTMLElement | null {
|
|
211
|
+
return this.watch.scroller;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Whether the pointer is dragging a thumb now. */
|
|
215
|
+
public get dragging(): boolean {
|
|
216
|
+
return this.drag !== null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Attaches to `scroller`, or to nothing; the scroller attached already stays attached. */
|
|
220
|
+
public attach(scroller: HTMLElement | null): void {
|
|
221
|
+
const previous = this.watch.scroller;
|
|
222
|
+
if (scroller === previous) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (previous) {
|
|
226
|
+
this.release(previous);
|
|
227
|
+
}
|
|
228
|
+
this.watch.follow(scroller);
|
|
229
|
+
if (!scroller) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
scroller.setAttribute(scrollerAttribute, '');
|
|
233
|
+
scroller.addEventListener('pointerdown', this.handlePointerDown, { capture: true });
|
|
234
|
+
scroller.addEventListener('pointermove', this.handlePointerMove, { passive: true });
|
|
235
|
+
scroller.addEventListener('pointerleave', this.handlePointerLeave, { passive: true });
|
|
236
|
+
this.y.offset = scroller.scrollTop;
|
|
237
|
+
this.x.offset = scroller.scrollLeft;
|
|
238
|
+
this.sync();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public detach(): void {
|
|
242
|
+
this.attach(null);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** Measures the scroller and places the rails now. */
|
|
246
|
+
public readonly sync = (): void => {
|
|
247
|
+
if (this.frame) {
|
|
248
|
+
cancelAnimationFrame(this.frame);
|
|
249
|
+
this.frame = 0;
|
|
250
|
+
}
|
|
251
|
+
const scroller = this.watch.scroller;
|
|
252
|
+
if (!scroller) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
this.insertRails(scroller);
|
|
256
|
+
const style = getComputedStyle(scroller);
|
|
257
|
+
this.rtl = style.direction === 'rtl';
|
|
258
|
+
const showY = scrollsAlong(style.overflowY)
|
|
259
|
+
&& scroller.scrollHeight - scroller.clientHeight > overflowThresholdPx;
|
|
260
|
+
const showX = scrollsAlong(style.overflowX)
|
|
261
|
+
&& scroller.scrollWidth - scroller.clientWidth > overflowThresholdPx;
|
|
262
|
+
this.y.shown = showY;
|
|
263
|
+
this.x.shown = showX;
|
|
264
|
+
this.y.rail.hidden = !showY;
|
|
265
|
+
this.x.rail.hidden = !showX;
|
|
266
|
+
if (!showY && !showX) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
// The rails cover the scroller's padding box. Both share the scroller's containing block,
|
|
270
|
+
// the positioned box around it, so its offsets place them.
|
|
271
|
+
const left = scroller.offsetLeft + scroller.clientLeft;
|
|
272
|
+
const top = scroller.offsetTop + scroller.clientTop;
|
|
273
|
+
const width = scroller.clientWidth;
|
|
274
|
+
const height = scroller.clientHeight;
|
|
275
|
+
const corner = showY && showX ? railBreadthPx : 0;
|
|
276
|
+
if (showY) {
|
|
277
|
+
const railHeight = height - corner;
|
|
278
|
+
this.placeRail(this.y.rail, this.rtl ? left : left + width - railBreadthPx, top, railBreadthPx, railHeight);
|
|
279
|
+
this.y.track = Math.max(0, railHeight - 2 * railEndInsetPx);
|
|
280
|
+
}
|
|
281
|
+
if (showX) {
|
|
282
|
+
const railWidth = width - corner;
|
|
283
|
+
this.placeRail(this.x.rail, this.rtl ? left + corner : left, top + height - railBreadthPx, railWidth, railBreadthPx);
|
|
284
|
+
this.x.track = Math.max(0, railWidth - 2 * railEndInsetPx);
|
|
285
|
+
}
|
|
286
|
+
this.placeThumbs();
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/** Measures the scroller in the next frame, once however often it is asked. */
|
|
290
|
+
public readonly invalidate = (): void => {
|
|
291
|
+
if (!this.frame && this.watch.scroller) {
|
|
292
|
+
this.frame = requestAnimationFrame(() => {
|
|
293
|
+
this.frame = 0;
|
|
294
|
+
this.sync();
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
private release(scroller: HTMLElement): void {
|
|
300
|
+
this.endDrag();
|
|
301
|
+
if (this.frame) {
|
|
302
|
+
cancelAnimationFrame(this.frame);
|
|
303
|
+
this.frame = 0;
|
|
304
|
+
}
|
|
305
|
+
scroller.removeEventListener('pointerdown', this.handlePointerDown, { capture: true });
|
|
306
|
+
scroller.removeEventListener('pointermove', this.handlePointerMove);
|
|
307
|
+
scroller.removeEventListener('pointerleave', this.handlePointerLeave);
|
|
308
|
+
scroller.removeAttribute(scrollerAttribute);
|
|
309
|
+
scroller.removeAttribute(grabAttribute);
|
|
310
|
+
for (const axis of [this.y, this.x]) {
|
|
311
|
+
clearTimeout(axis.scrollingTimer);
|
|
312
|
+
axis.scrollingTimer = undefined;
|
|
313
|
+
axis.rail.removeAttribute('data-scrolling');
|
|
314
|
+
axis.rail.removeAttribute('data-hovered');
|
|
315
|
+
axis.rail.hidden = true;
|
|
316
|
+
axis.shown = false;
|
|
317
|
+
axis.rail.remove();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Keeps the rails right after the scroller, where a render that moved things may have left them. */
|
|
322
|
+
private insertRails(scroller: HTMLElement): void {
|
|
323
|
+
if (scroller.nextElementSibling !== this.y.rail || this.y.rail.nextElementSibling !== this.x.rail) {
|
|
324
|
+
scroller.after(this.y.rail, this.x.rail);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
private placeRail(rail: HTMLElement, left: number, top: number, width: number, height: number): void {
|
|
329
|
+
setStyle(rail, 'left', `${left}px`);
|
|
330
|
+
setStyle(rail, 'top', `${top}px`);
|
|
331
|
+
setStyle(rail, 'width', `${width}px`);
|
|
332
|
+
setStyle(rail, 'height', `${height}px`);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
private placeThumbs(): void {
|
|
336
|
+
const scroller = this.watch.scroller;
|
|
337
|
+
if (!scroller) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (this.y.shown) {
|
|
341
|
+
const max = scroller.scrollHeight - scroller.clientHeight;
|
|
342
|
+
this.placeThumb(this.y, scroller.clientHeight / scroller.scrollHeight, max > 0 ? scroller.scrollTop / max : 0);
|
|
343
|
+
}
|
|
344
|
+
if (this.x.shown) {
|
|
345
|
+
const max = scroller.scrollWidth - scroller.clientWidth;
|
|
346
|
+
// Scrolled from right to left, scrollLeft runs from 0 at the start to -max at the end.
|
|
347
|
+
const progress = max > 0 ? (this.rtl ? 1 + scroller.scrollLeft / max : scroller.scrollLeft / max) : 0;
|
|
348
|
+
this.placeThumb(this.x, scroller.clientWidth / scroller.scrollWidth, progress);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private placeThumb(axis: IOverlayAxis, visibleShare: number, progress: number): void {
|
|
353
|
+
const length = Math.min(axis.track, Math.max(minThumbPx, axis.track * visibleShare));
|
|
354
|
+
const offset = railEndInsetPx + (axis.track - length) * Math.min(1, Math.max(0, progress));
|
|
355
|
+
axis.length = length;
|
|
356
|
+
setStyle(axis.thumb, axis.vertical ? 'height' : 'width', `${length}px`);
|
|
357
|
+
setStyle(axis.thumb, 'transform', axis.vertical ? `translateY(${offset}px)` : `translateX(${offset}px)`);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
private handleScroll(): void {
|
|
361
|
+
const scroller = this.watch.scroller;
|
|
362
|
+
if (!scroller) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (scroller.scrollTop !== this.y.offset) {
|
|
366
|
+
this.y.offset = scroller.scrollTop;
|
|
367
|
+
this.markScrolling(this.y);
|
|
368
|
+
}
|
|
369
|
+
if (scroller.scrollLeft !== this.x.offset) {
|
|
370
|
+
this.x.offset = scroller.scrollLeft;
|
|
371
|
+
this.markScrolling(this.x);
|
|
372
|
+
}
|
|
373
|
+
this.placeThumbs();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
private markScrolling(axis: IOverlayAxis): void {
|
|
377
|
+
axis.rail.setAttribute('data-scrolling', '');
|
|
378
|
+
clearTimeout(axis.scrollingTimer);
|
|
379
|
+
axis.scrollingTimer = setTimeout(() => {
|
|
380
|
+
axis.scrollingTimer = undefined;
|
|
381
|
+
axis.rail.removeAttribute('data-scrolling');
|
|
382
|
+
}, scrollingHoldMs);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** The axis whose thumb lies under the point: within the rail's breadth and the thumb's length. */
|
|
386
|
+
private thumbAt(clientX: number, clientY: number): IOverlayAxis | null {
|
|
387
|
+
for (const axis of [this.y, this.x]) {
|
|
388
|
+
if (!axis.shown) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const rail = axis.rail.getBoundingClientRect();
|
|
392
|
+
// A host may hide a rail outright, in which case it has no box.
|
|
393
|
+
if (!rail.width || !rail.height) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
const thumb = axis.thumb.getBoundingClientRect();
|
|
397
|
+
const hit = axis.vertical
|
|
398
|
+
? clientX >= rail.left && clientX <= rail.right && clientY >= thumb.top && clientY <= thumb.bottom
|
|
399
|
+
: clientY >= rail.top && clientY <= rail.bottom && clientX >= thumb.left && clientX <= thumb.right;
|
|
400
|
+
if (hit) {
|
|
401
|
+
return axis;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
private setHovered(axis: IOverlayAxis | null): void {
|
|
408
|
+
for (const candidate of [this.y, this.x]) {
|
|
409
|
+
candidate.rail.toggleAttribute('data-hovered', candidate === axis);
|
|
410
|
+
}
|
|
411
|
+
this.watch.scroller?.toggleAttribute(grabAttribute, axis !== null);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
private readonly handlePointerMove = (event: PointerEvent): void => {
|
|
415
|
+
if (!this.drag) {
|
|
416
|
+
this.setHovered(event.pointerType === 'touch' ? null : this.thumbAt(event.clientX, event.clientY));
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
private readonly handlePointerLeave = (): void => {
|
|
421
|
+
if (!this.drag) {
|
|
422
|
+
this.setHovered(null);
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
private readonly handlePointerDown = (event: PointerEvent): void => {
|
|
427
|
+
const scroller = this.watch.scroller;
|
|
428
|
+
if (!scroller || this.drag || event.button !== 0 || event.pointerType === 'touch') {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
const axis = this.thumbAt(event.clientX, event.clientY);
|
|
432
|
+
if (!axis) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
event.preventDefault();
|
|
436
|
+
event.stopImmediatePropagation();
|
|
437
|
+
const max = axis.vertical
|
|
438
|
+
? scroller.scrollHeight - scroller.clientHeight
|
|
439
|
+
: scroller.scrollWidth - scroller.clientWidth;
|
|
440
|
+
const travel = axis.track - axis.length;
|
|
441
|
+
scroller.setPointerCapture(event.pointerId);
|
|
442
|
+
this.drag = {
|
|
443
|
+
axis,
|
|
444
|
+
pointerId: event.pointerId,
|
|
445
|
+
startPointer: axis.vertical ? event.clientY : event.clientX,
|
|
446
|
+
startScroll: axis.vertical ? scroller.scrollTop : scroller.scrollLeft,
|
|
447
|
+
ratio: travel > 0 ? max / travel : 0,
|
|
448
|
+
};
|
|
449
|
+
scroller.setAttribute(dragAttribute, '');
|
|
450
|
+
axis.rail.setAttribute('data-dragging', '');
|
|
451
|
+
this.setHovered(axis);
|
|
452
|
+
scroller.addEventListener('pointermove', this.handleDragMove, { capture: true });
|
|
453
|
+
scroller.addEventListener('pointerup', this.handleDragEnd, { capture: true });
|
|
454
|
+
scroller.addEventListener('pointercancel', this.handleDragEnd, { capture: true });
|
|
455
|
+
scroller.addEventListener('lostpointercapture', this.handleDragEnd, { capture: true });
|
|
456
|
+
scroller.addEventListener('selectstart', this.preventDefault, { capture: true });
|
|
457
|
+
scroller.addEventListener('dragstart', this.preventDefault, { capture: true });
|
|
458
|
+
for (const type of orphanedDragEnds) {
|
|
459
|
+
window.addEventListener(type, this.handleOrphanedDragEnd, { capture: true });
|
|
460
|
+
}
|
|
461
|
+
if (!this.suppressingClick) {
|
|
462
|
+
this.suppressingClick = true;
|
|
463
|
+
window.addEventListener('click', this.suppressClick, { capture: true });
|
|
464
|
+
}
|
|
465
|
+
this.options.onDrag?.(true);
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
private readonly handleDragMove = (event: PointerEvent): void => {
|
|
469
|
+
const drag = this.drag;
|
|
470
|
+
const scroller = this.watch.scroller;
|
|
471
|
+
if (!drag || !scroller || event.pointerId !== drag.pointerId) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
event.preventDefault();
|
|
475
|
+
event.stopImmediatePropagation();
|
|
476
|
+
const moved = (drag.axis.vertical ? event.clientY : event.clientX) - drag.startPointer;
|
|
477
|
+
const target = drag.startScroll + moved * drag.ratio;
|
|
478
|
+
scroller.scrollTo(drag.axis.vertical
|
|
479
|
+
? { top: target, behavior: 'instant' }
|
|
480
|
+
: { left: target, behavior: 'instant' });
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Ends a drag whose scroller left the document while the thumb was held: the scroller lost the
|
|
485
|
+
* pointer capture, so the release passes the window only, and a release outside the window
|
|
486
|
+
* reaches nothing at all, which the next press shows.
|
|
487
|
+
*/
|
|
488
|
+
private readonly handleOrphanedDragEnd = (): void => {
|
|
489
|
+
if (this.drag && !this.watch.scroller?.isConnected) {
|
|
490
|
+
this.endDrag();
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
private readonly handleDragEnd = (event: PointerEvent): void => {
|
|
495
|
+
if (!this.drag || event.pointerId !== this.drag.pointerId) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
if (event.type === 'pointerup') {
|
|
499
|
+
event.stopImmediatePropagation();
|
|
500
|
+
}
|
|
501
|
+
this.endDrag();
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
private endDrag(): void {
|
|
505
|
+
const drag = this.drag;
|
|
506
|
+
const scroller = this.watch.scroller;
|
|
507
|
+
if (!drag || !scroller) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
this.drag = null;
|
|
511
|
+
scroller.removeEventListener('pointermove', this.handleDragMove, { capture: true });
|
|
512
|
+
scroller.removeEventListener('pointerup', this.handleDragEnd, { capture: true });
|
|
513
|
+
scroller.removeEventListener('pointercancel', this.handleDragEnd, { capture: true });
|
|
514
|
+
scroller.removeEventListener('lostpointercapture', this.handleDragEnd, { capture: true });
|
|
515
|
+
scroller.removeEventListener('selectstart', this.preventDefault, { capture: true });
|
|
516
|
+
scroller.removeEventListener('dragstart', this.preventDefault, { capture: true });
|
|
517
|
+
for (const type of orphanedDragEnds) {
|
|
518
|
+
window.removeEventListener(type, this.handleOrphanedDragEnd, { capture: true });
|
|
519
|
+
}
|
|
520
|
+
if (scroller.hasPointerCapture(drag.pointerId)) {
|
|
521
|
+
scroller.releasePointerCapture(drag.pointerId);
|
|
522
|
+
}
|
|
523
|
+
scroller.removeAttribute(dragAttribute);
|
|
524
|
+
drag.axis.rail.removeAttribute('data-dragging');
|
|
525
|
+
this.setHovered(null);
|
|
526
|
+
// The click a press and release make comes in the same task as the release; a release
|
|
527
|
+
// without one leaves nothing to take.
|
|
528
|
+
setTimeout(this.stopSuppressingClick, 0);
|
|
529
|
+
this.options.onDrag?.(false);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
private readonly suppressClick = (event: MouseEvent): void => {
|
|
533
|
+
event.preventDefault();
|
|
534
|
+
event.stopImmediatePropagation();
|
|
535
|
+
this.stopSuppressingClick();
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
private readonly stopSuppressingClick = (): void => {
|
|
539
|
+
if (this.suppressingClick && !this.drag) {
|
|
540
|
+
this.suppressingClick = false;
|
|
541
|
+
window.removeEventListener('click', this.suppressClick, { capture: true });
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
private readonly preventDefault = (event: Event): void => {
|
|
546
|
+
event.preventDefault();
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Overlay scrollbars on a scroller a Lit host renders: the controller attaches `OverlayScrollbars`
|
|
552
|
+
* to the scroller the host names, from its first render on, and to a scroller the host renders
|
|
553
|
+
* anew. It measures after every render of the host, in the next frame.
|
|
554
|
+
*
|
|
555
|
+
* ```ts
|
|
556
|
+
* public static styles = [themeDefaultStyles, overlayScrollbarStyles, css`
|
|
557
|
+
* .listFrame { position: relative; flex: 1; min-height: 0; }
|
|
558
|
+
* .list { height: 100%; overflow-y: auto; }
|
|
559
|
+
* `];
|
|
560
|
+
*
|
|
561
|
+
* private readonly scrollbars = new OverlayScrollbarController(this, () => this.shadowRoot?.querySelector('.list'));
|
|
562
|
+
*
|
|
563
|
+
* public render() {
|
|
564
|
+
* return html`<div class="listFrame"><div class="list">…</div></div>`;
|
|
565
|
+
* }
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
export class OverlayScrollbarController implements TReactiveController {
|
|
569
|
+
private connected = false;
|
|
570
|
+
private readonly scrollbars: OverlayScrollbars;
|
|
571
|
+
|
|
572
|
+
constructor(
|
|
573
|
+
private readonly host: DeesElement,
|
|
574
|
+
private readonly scrollerArg: () => HTMLElement | null | undefined,
|
|
575
|
+
options: IOverlayScrollbarsOptions = {},
|
|
576
|
+
) {
|
|
577
|
+
this.scrollbars = new OverlayScrollbars(options);
|
|
578
|
+
host.addController(this);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** Whether the pointer is dragging a thumb now. */
|
|
582
|
+
public get dragging(): boolean {
|
|
583
|
+
return this.scrollbars.dragging;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/** A host that connects again renders nothing new, so it is attached once its render is done. */
|
|
587
|
+
public hostConnected(): void {
|
|
588
|
+
this.connected = true;
|
|
589
|
+
void this.host.updateComplete.then(() => {
|
|
590
|
+
if (this.connected) {
|
|
591
|
+
this.scrollbars.attach(this.scrollerArg() ?? null);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/** Every render may change the scroller or its content. */
|
|
597
|
+
public hostUpdated(): void {
|
|
598
|
+
if (this.connected) {
|
|
599
|
+
this.scrollbars.attach(this.scrollerArg() ?? null);
|
|
600
|
+
this.scrollbars.invalidate();
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
public hostDisconnected(): void {
|
|
605
|
+
this.connected = false;
|
|
606
|
+
this.scrollbars.detach();
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/** Measures the scroller and places the rails now, as `OverlayScrollbars.sync()` does. */
|
|
610
|
+
public readonly sync = (): void => {
|
|
611
|
+
this.scrollbars.sync();
|
|
612
|
+
};
|
|
613
|
+
}
|