@@ -282,3 +282,48 @@ export function dragToReorder(root, scope, onMove) {
282282 scope . on ( document , 'pointercancel' , end ) ;
283283 return ( ) => { const was = eatClick ; eatClick = false ; return was ; } ;
284284}
285+
286+ /**
287+ * The hands of cards scroll sideways with a mouse too: the wheel scrolls the row under the pointer (until
288+ * it reaches an end, then the page scrolls on), and a mouse can drag the row. Touch already swipes it.
289+ * Returns eat(): true once just after a drag, so the click that ends it doesn't also play a card.
290+ */
291+ export function mouseScroll ( root , scope ) {
292+ let D = null , eatClick = false ;
293+ scope . on ( root , 'wheel' , ( e ) => {
294+ const row = e . target . closest ( '.hand' ) ;
295+ if ( ! row || e . ctrlKey || Math . abs ( e . deltaY ) <= Math . abs ( e . deltaX ) ) return ;
296+ const room = row . scrollWidth - row . clientWidth ;
297+ if ( room <= 0 || ( e . deltaY < 0 && row . scrollLeft <= 0 ) || ( e . deltaY > 0 && row . scrollLeft >= room - 1 ) ) return ;
298+ e . preventDefault ( ) ;
299+ row . scrollLeft += e . deltaY ;
300+ } , { passive : false } ) ;
301+ scope . on ( root , 'pointerdown' , ( e ) => {
302+ const row = e . target . closest ( '.hand' ) ;
303+ if ( ! row || e . pointerType !== 'mouse' || e . button !== 0 || row . scrollWidth <= row . clientWidth ) return ;
304+ D = { row, x : e . clientX , left : row . scrollLeft , moved : false , id : e . pointerId } ;
305+ } ) ;
306+ scope . on ( document , 'pointermove' , ( e ) => {
307+ if ( ! D || e . pointerId !== D . id ) return ;
308+ const dx = e . clientX - D . x ;
309+ if ( ! D . moved ) {
310+ if ( Math . abs ( dx ) < 6 ) return ;
311+ D . moved = true ;
312+ D . row . classList . add ( 'grabbing' ) ; // snapping off while it's held, so it follows the mouse
313+ }
314+ e . preventDefault ( ) ;
315+ D . row . scrollLeft = D . left - dx ;
316+ } ) ;
317+ const end = ( e ) => {
318+ if ( ! D || e . pointerId !== D . id ) return ;
319+ const d = D ;
320+ D = null ;
321+ if ( ! d . moved ) return ;
322+ d . row . classList . remove ( 'grabbing' ) ;
323+ eatClick = true ;
324+ scope . later ( ( ) => { eatClick = false ; } , 80 ) ;
325+ } ;
326+ scope . on ( document , 'pointerup' , end ) ;
327+ scope . on ( document , 'pointercancel' , end ) ;
328+ return ( ) => { const was = eatClick ; eatClick = false ; return was ; } ;
329+ }
0 commit comments