@jsenv/dom 0.17.41 → 0.17.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/jsenv_dom.js +89 -0
  2. package/package.json +1 -1
package/dist/jsenv_dom.js CHANGED
@@ -14163,6 +14163,31 @@ const WHEEL_NEXT_STEP_DELTA = 600;
14163
14163
  // slides. Two events in a row are asked for rather than one, because a hand
14164
14164
  // wavers and momentum does not.
14165
14165
  const WHEEL_FADE_RUN = 2;
14166
+ // …and the same fact read the other way: momentum only ever weakens, so a
14167
+ // stream already recognized as momentum that GROWS twice in a row is a hand
14168
+ // pushing again — a second swipe thrown while the tail of the first is still
14169
+ // streaming. The browser sees one unbroken burst (the tail never went silent),
14170
+ // but to the hand these are two gestures, and the second is answered like a
14171
+ // first event: with a screen, now, not with credit towards one.
14172
+ const WHEEL_REGROW_RUN = 2;
14173
+ // A hand scrolling the OTHER axis over that same tail is a new gesture too,
14174
+ // and one that is not ours — but it has to be told apart from the tail's own
14175
+ // wobble: at the end of a fade the deltas are a pixel or two on each axis, and
14176
+ // read alone such an event says "the other axis" as easily as it says nothing.
14177
+ // Three things separate a scroll from those crumbs, and all three are asked
14178
+ // for before an event is handed back:
14179
+ // - the other axis clearly dominates the event (the same bar a drag uses to
14180
+ // give up its press) — a diagonal crumb says nothing;
14181
+ // - the event is the size of a hand (WHEEL_CROSS_CONFIRM_DELTA — crumbs never
14182
+ // reach it), or the run is GROWING event over event, which is a scroll
14183
+ // ramping up from rest and never what decay looks like;
14184
+ // - and it is a RUN (one more event for the growing read, which starts from
14185
+ // sizes a crumb also has): wobble is isolated, a scroll insists.
14186
+ // What the run costs a real scroll is its first event or two — a few pixels,
14187
+ // one notch of a stepped wheel; what it saves a slide is its own scroller
14188
+ // creeping under a travel, a header detaching from the edge of the box.
14189
+ const WHEEL_CROSS_RUN = 2;
14190
+ const WHEEL_CROSS_CONFIRM_DELTA = 10;
14166
14191
 
14167
14192
  /**
14168
14193
  * A travel asked for with a wheel, and it asks for a WHOLE ONE.
@@ -14307,11 +14332,48 @@ const watchWheelTravel = (element, {
14307
14332
  pushed: 0,
14308
14333
  lastMagnitude: 0,
14309
14334
  fadeRun: 0,
14335
+ growRun: 0,
14336
+ crossRun: 0,
14337
+ crossMagnitude: 0,
14338
+ crossHandedBack: false,
14339
+ faded: false,
14310
14340
  stepped: false
14311
14341
  };
14312
14342
  document.documentElement.setAttribute(GESTURE_ATTRIBUTE, "");
14313
14343
  document.documentElement.setAttribute(WALKING_ATTRIBUTE, axis);
14314
14344
  }
14345
+ // The other axis, on a stream that is momentum only: a hand is never
14346
+ // perfectly straight, so cross-axis events WITHIN a push are the push's own
14347
+ // wobble and are swallowed below — but once our axis has faded to a tail,
14348
+ // a hand pushing the other way is a NEW gesture, and on an axis this box
14349
+ // does not travel it is not ours at all: it belongs to whatever scrolls
14350
+ // under the pointer, and it is handed back untouched. Not swallowed, and
14351
+ // not renewing the claim either — an ignored scroll must not keep alive
14352
+ // the very gesture that ignores it, while the tail of ours goes on being
14353
+ // absorbed by the events still on our axis. Only a scroll is handed back,
14354
+ // though, never the tail's own wobble — see WHEEL_CROSS_RUN.
14355
+ if (axis !== gesture.axis && gesture.faded && !axes.includes(axis)) {
14356
+ if (gesture.crossHandedBack) {
14357
+ // Already recognized as a scroll: the whole rest of it is its own.
14358
+ return;
14359
+ }
14360
+ const ownDelta = Math.abs(gesture.axis === "x" ? wheelEvent.deltaX : wheelEvent.deltaY);
14361
+ const crossDelta = Math.abs(delta);
14362
+ const dominant = crossDelta > ownDelta * AXIS_CROSS_DOMINANCE;
14363
+ const handSized = crossDelta >= WHEEL_CROSS_CONFIRM_DELTA;
14364
+ const growing = crossDelta > gesture.crossMagnitude;
14365
+ if (dominant && (handSized || growing)) {
14366
+ gesture.crossRun += 1;
14367
+ gesture.crossMagnitude = crossDelta;
14368
+ if (gesture.crossRun >= (handSized ? WHEEL_CROSS_RUN : WHEEL_CROSS_RUN + 1)) {
14369
+ gesture.crossHandedBack = true;
14370
+ return;
14371
+ }
14372
+ } else {
14373
+ gesture.crossRun = 0;
14374
+ gesture.crossMagnitude = 0;
14375
+ }
14376
+ }
14315
14377
  // Ours from here, on both axes: what the browser would do with the leftover
14316
14378
  // — scroll the page behind the box, bounce it, go back in history — is one
14317
14379
  // gesture answered twice.
@@ -14326,12 +14388,18 @@ const watchWheelTravel = (element, {
14326
14388
  // axis was decided when the gesture set off.
14327
14389
  return;
14328
14390
  }
14391
+ // Back on our axis: whatever cross-axis run was building was wobble.
14392
+ gesture.crossRun = 0;
14393
+ gesture.crossMagnitude = 0;
14394
+ gesture.crossHandedBack = false;
14329
14395
  if (sign !== gesture.sign) {
14330
14396
  // Turned around: what was adding up was going the other way.
14331
14397
  gesture.sign = sign;
14332
14398
  gesture.pushed = 0;
14333
14399
  gesture.lastMagnitude = 0;
14334
14400
  gesture.fadeRun = 0;
14401
+ gesture.growRun = 0;
14402
+ gesture.faded = false;
14335
14403
  gesture.stepped = false;
14336
14404
  }
14337
14405
  if (!gesture.stepped) {
@@ -14350,11 +14418,32 @@ const watchWheelTravel = (element, {
14350
14418
  const magnitude = Math.abs(delta);
14351
14419
  if (magnitude < gesture.lastMagnitude) {
14352
14420
  gesture.fadeRun += 1;
14421
+ gesture.growRun = 0;
14422
+ if (gesture.fadeRun >= WHEEL_FADE_RUN) {
14423
+ // Momentum, recognized — and remembered past the next growth: fadeRun
14424
+ // is transient (one louder event resets it), while what the regrow
14425
+ // rule below needs to know is that a tail WAS established at all.
14426
+ gesture.faded = true;
14427
+ }
14353
14428
  } else if (magnitude > gesture.lastMagnitude) {
14354
14429
  // Back up again — a hand asking for more. Momentum never does this.
14355
14430
  gesture.fadeRun = 0;
14431
+ gesture.growRun += 1;
14356
14432
  }
14357
14433
  gesture.lastMagnitude = magnitude;
14434
+ // A second push, thrown while the tail of the first still streams (see
14435
+ // WHEEL_REGROW_RUN): a new gesture to the hand, whatever the stream says.
14436
+ if (gesture.faded && gesture.growRun >= WHEEL_REGROW_RUN) {
14437
+ gesture.faded = false;
14438
+ gesture.growRun = 0;
14439
+ gesture.pushed = 0;
14440
+ onStep({
14441
+ axis: gesture.axis,
14442
+ sign: gesture.sign,
14443
+ event: wheelEvent
14444
+ });
14445
+ return;
14446
+ }
14358
14447
  if (gesture.fadeRun >= WHEEL_FADE_RUN) {
14359
14448
  return;
14360
14449
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/dom",
3
- "version": "0.17.41",
3
+ "version": "0.17.42",
4
4
  "type": "module",
5
5
  "description": "DOM utilities for writing frontend code",
6
6
  "repository": {