@jsenv/dom 0.17.75 → 0.17.76

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 +69 -8
  2. package/package.json +1 -1
package/dist/jsenv_dom.js CHANGED
@@ -12399,10 +12399,12 @@ const DRAG_COMMIT_RATIO = 0.3;
12399
12399
  // a movement from a tap that shook.
12400
12400
  const DRAG_DRIFT_VELOCITY = 0.03;
12401
12401
  const DRAG_DRIFT_DISTANCE = 8;
12402
- // Thrown back: a hand moving AWAY from what it was bringing in this fast asks
12403
- // for it to be put back, whatever the distance already covered. Well above the
12404
- // drift bar, so a hand merely wavering as it lets go does not read as a throw.
12405
- const DRAG_THROW_BACK_VELOCITY = 0.3;
12402
+ // Thrown: a hand moving this fast as it lets go says where things go, whatever
12403
+ // the distance already covered. AWAY from what it was bringing in, it asks for
12404
+ // it to be put back (travelsAfter); the way a travel it caught in flight was
12405
+ // already going, it asks for the one after (see thrownOn). Well above the drift
12406
+ // bar, so a hand merely wavering as it lets go does not read as a throw.
12407
+ const DRAG_THROW_VELOCITY = 0.3;
12406
12408
  // Pulling towards nothing: what travels follows at a fraction of the finger, so
12407
12409
  // the gesture is answered (something moves) while saying there is nothing that
12408
12410
  // way. Let go and it comes back — a wall one can lean on, never walk through.
@@ -12672,7 +12674,7 @@ const travelsAfter = ({
12672
12674
  // two thirds and thrown back still arrives: the gesture was read as the
12673
12675
  // place it was let go of rather than as a movement.
12674
12676
  if (
12675
- Math.abs(velocity) > DRAG_THROW_BACK_VELOCITY &&
12677
+ Math.abs(velocity) > DRAG_THROW_VELOCITY &&
12676
12678
  Math.sign(velocity) !== sign
12677
12679
  ) {
12678
12680
  return false;
@@ -12687,6 +12689,27 @@ const travelsAfter = ({
12687
12689
  return Math.abs(pulled) > size * commitRatio;
12688
12690
  };
12689
12691
 
12692
+ // A travel caught in flight and thrown on the way it was already going: a
12693
+ // second push, and it asks for the screen AFTER the one on its way — two
12694
+ // gestures, two screens, as a second push over a wheel's tail is. Read as the
12695
+ // verdict above, it only confirms what was already arriving: the throw stops
12696
+ // the travel at the press and lets it go on to the same place, and what the
12697
+ // hand feels is its second swipe swallowed. The hand has to have moved that way
12698
+ // by more than a tremor, so a travel merely touched still carries on to where
12699
+ // it was going (see the slack rule in travelsAfter).
12700
+ const thrownOn = ({ pulled, slack, velocity, towardsSomething, cancelled }) => {
12701
+ if (!slack || cancelled || !towardsSomething) {
12702
+ return false;
12703
+ }
12704
+ const way = Math.sign(slack);
12705
+ return (
12706
+ Math.sign(pulled) === way &&
12707
+ (pulled - slack) * way >= DRAG_START_THRESHOLD &&
12708
+ Math.sign(velocity) === way &&
12709
+ Math.abs(velocity) > DRAG_THROW_VELOCITY
12710
+ );
12711
+ };
12712
+
12690
12713
  /**
12691
12714
  * Read a press, and tell the caller what the hand is doing with it.
12692
12715
  *
@@ -12731,7 +12754,7 @@ const travelsAfter = ({
12731
12754
  * @param {(detail: {axis: string, pulled: number, size: number, progress: number, event: PointerEvent}) => void} options.onPull
12732
12755
  * - the finger has moved. `pulled` is in px from the resting place, `progress`
12733
12756
  * the same as a fraction of the box, signed the same way.
12734
- * @param {(detail: {axis: string, sign: number, event: PointerEvent}) => false|{size: number, travelBack?: boolean, travelOn?: boolean}} [options.onEdge]
12757
+ * @param {(detail: {axis: string, sign: number, thrown: boolean, event: PointerEvent}) => false|{size: number, travelBack?: boolean, travelOn?: boolean}} [options.onEdge]
12735
12758
  * - the hand has reached an end of the box it holds and keeps going: `sign`
12736
12759
  * says which one — the far edge, a box walked whole, or its start, a box
12737
12760
  * walked back to where it began. Answer with the geometry of the box that
@@ -12739,9 +12762,15 @@ const travelsAfter = ({
12739
12762
  * become its first ones, so nothing is spent twice and the hand feels one
12740
12763
  * continuous movement. Answer `false` (or leave it out) for a wall — the
12741
12764
  * gesture stays on the box it has and leans on it.
12765
+ * `thrown`: the hand did not walk there, it let go throwing a travel it had
12766
+ * caught on the way it was already going (see thrownOn). The box is asked for
12767
+ * at the release, with the picture still short of the end; answer `false` if
12768
+ * it cannot be handed over from there, and the travel simply arrives.
12742
12769
  * @param {(detail: {axis: string, pulled: number, size: number, sign: number, travels: boolean, cancelled: boolean, event: PointerEvent}) => void} options.onEnd
12743
12770
  * - the finger is off. `travels` is the gesture's answer: carry on to what was
12744
- * being pulled in, or put things back.
12771
+ * being pulled in, or put things back. `sign` is the side of what was being
12772
+ * pulled in — the side `pulled` is on, except after a throw handed over at
12773
+ * the release, where the picture still stands short of the new box.
12745
12774
  * @param {() => void} [options.onGiveUp] - the press is over without ever
12746
12775
  * becoming a travel: it stayed still, leaned the wrong way, or `onStart`
12747
12776
  * refused it. Nothing was painted and nothing has to be put back — this is
@@ -12852,10 +12881,11 @@ const startDragToTravel = (
12852
12881
  // from where the finger IS: nothing is spent twice, and the gesture is one
12853
12882
  // movement rather than a wall the hand had to let go of to cross.
12854
12883
  // Returns where the new box stands, or null when there is nothing that way.
12855
- const relayTo = (sign, distance, gestureInfo) => {
12884
+ const relayTo = (sign, distance, gestureInfo, { thrown = false } = {}) => {
12856
12885
  const next = onEdge({
12857
12886
  axis: travel.axis,
12858
12887
  sign,
12888
+ thrown,
12859
12889
  event: gestureInfo.dragEvent,
12860
12890
  });
12861
12891
  if (!next || !next.size) {
@@ -13062,6 +13092,37 @@ const startDragToTravel = (
13062
13092
  axis === "x" ? gestureInfo.velocityX : gestureInfo.velocityY;
13063
13093
  const releaseEvent = gestureInfo.releaseEvent || gestureInfo.dragEvent;
13064
13094
  const { cancelled } = gestureInfo;
13095
+ if (thrownOn({ pulled, slack, velocity, towardsSomething, cancelled })) {
13096
+ const sign = pulled > 0 ? 1 : -1;
13097
+ // Where the picture stands, said from the box past the one in hand:
13098
+ // short of it by what is left of the travel that was caught.
13099
+ const relayed = relayTo(sign, pulled - sign * size, gestureInfo, {
13100
+ thrown: true,
13101
+ });
13102
+ if (relayed !== null) {
13103
+ // Nothing moves: the same place, measured from the new box — so the
13104
+ // caller's picture of the gesture agrees with it before it is let go.
13105
+ onPull({
13106
+ axis,
13107
+ pulled: relayed,
13108
+ size: travel.size,
13109
+ progress: relayed / travel.size,
13110
+ event: releaseEvent,
13111
+ });
13112
+ onEnd({
13113
+ axis,
13114
+ pulled: relayed,
13115
+ size: travel.size,
13116
+ // The way it was thrown, not the side the picture stands on: it
13117
+ // still sits short of the box it was bringing in.
13118
+ sign,
13119
+ travels: true,
13120
+ cancelled: false,
13121
+ event: releaseEvent,
13122
+ });
13123
+ return;
13124
+ }
13125
+ }
13065
13126
  onEnd({
13066
13127
  axis,
13067
13128
  pulled,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/dom",
3
- "version": "0.17.75",
3
+ "version": "0.17.76",
4
4
  "type": "module",
5
5
  "description": "DOM utilities for writing frontend code",
6
6
  "repository": {