@jsenv/dom 0.17.94 → 0.17.95

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 +39 -10
  2. package/package.json +1 -1
package/dist/jsenv_dom.js CHANGED
@@ -13253,6 +13253,14 @@ const startDragToTravel = (
13253
13253
  if (movingAxis && !axesLeft.includes(movingAxis)) {
13254
13254
  return null;
13255
13255
  }
13256
+ // A link and an image are draggable without anyone asking, and the browser
13257
+ // starts that drag about 3px in, under the threshold below: it cancels the
13258
+ // pointer and keeps the rest of the press, so the travel never forms. Refused
13259
+ // for this press only — one excluded above, or left to a box inside, keeps it.
13260
+ const refuseNativeDrag = (dragStartEvent) => {
13261
+ dragStartEvent.preventDefault();
13262
+ };
13263
+ element.addEventListener("dragstart", refuseNativeDrag);
13256
13264
  const startThreshold =
13257
13265
  pointerDownEvent.pointerType === "mouse"
13258
13266
  ? DRAG_START_THRESHOLD
@@ -13278,6 +13286,7 @@ const startDragToTravel = (
13278
13286
  clearTimeout(holdTimeout);
13279
13287
  document.documentElement.removeAttribute(GESTURE_ATTRIBUTE);
13280
13288
  document.documentElement.removeAttribute(WALKING_ATTRIBUTE);
13289
+ element.removeEventListener("dragstart", refuseNativeDrag);
13281
13290
  window.removeEventListener("pointerup", onPressOver);
13282
13291
  window.removeEventListener("pointercancel", onPressOver);
13283
13292
  };
@@ -14091,10 +14100,11 @@ const findPanZoomSurface = (element) => {
14091
14100
  * @param {boolean|"kept"} [options.afterHold=false] Whether a FINGER must be held
14092
14101
  * still before it pans, the page keeping its scroll until then. For a surface
14093
14102
  * standing in something that scrolls; a mouse pans by travelling either way.
14094
- * `"kept"` asks for the wait once: from the moment the surface has the hand it
14095
- * pans on contact, and it asks again only after a pointer has gone down away
14096
- * from it. `data-hand-kept` is on the element for as long as it holds the hand
14097
- * that way, a hand touching it or not.
14103
+ * `"kept"` asks for the wait once: from the moment a finger has given the
14104
+ * surface the hand it pans on contact, and it asks again only after a pointer
14105
+ * has gone down away from it. `data-hand-kept` is on the element for as long
14106
+ * as it holds the hand that way, a hand touching it or not; a mouse pan never
14107
+ * sets it.
14098
14108
  * @param {"auto"|"always"} [options.wheelZoom="auto"] Whether a BARE wheel zooms.
14099
14109
  * `"auto"` gives it to whatever scrolls around the surface when there is one,
14100
14110
  * and zooms when there is none; `"always"` takes it back, for a surface that
@@ -14115,8 +14125,8 @@ const installPanZoom = (
14115
14125
  } = {},
14116
14126
  ) => {
14117
14127
  // Whether a finger still owes the wait. Constant under a plain `afterHold`;
14118
- // under `"kept"` it is spent the first time the surface is given the hand and
14119
- // asked for again once the hand has gone elsewhere.
14128
+ // under `"kept"` it is spent the first time a finger gives the surface the hand
14129
+ // and asked for again once the hand has gone elsewhere.
14120
14130
  let holdIsOwed = Boolean(afterHold);
14121
14131
  const reflectHoldOwed = () => {
14122
14132
  // What a touch may do is settled before it lands, so the mode is in the DOM
@@ -14195,10 +14205,14 @@ const installPanZoom = (
14195
14205
 
14196
14206
  const activate = (anchorWhere, event) => {
14197
14207
  active = true;
14198
- if (afterHold === "kept" && holdIsOwed && onPan) {
14199
- // Asked for and given: whatever proved it — the hold, a second finger, a
14200
- // mouse travelling — the surface is the hand's from here. What it keeps
14201
- // is the pan on contact, which a surface that does not pan has none of.
14208
+ if (
14209
+ afterHold === "kept" &&
14210
+ [...pointers.values()].some((pointer) => pointer.waitsForHold)
14211
+ ) {
14212
+ // Spent by the finger that owed it, whether the hold or a second finger
14213
+ // proved it: the surface is the hand's from here. A mouse never owed the
14214
+ // wait, so it neither spends it nor marks it — and a surface that does not
14215
+ // pan asks no finger to wait, having no pan on contact to keep.
14202
14216
  keepTheHand();
14203
14217
  }
14204
14218
  for (const pointer of pointers.values()) {
@@ -14379,6 +14393,16 @@ const installPanZoom = (
14379
14393
  }
14380
14394
  };
14381
14395
 
14396
+ // A link and an image are draggable without anyone asking, and the browser
14397
+ // starts that drag about 3px in, under `threshold`: it cancels the pointer and
14398
+ // keeps the rest of the press, so the pan never forms. Refused only while the
14399
+ // surface reads a press — one yielded to something inside never got here.
14400
+ const refuseNativeDrag = (dragStartEvent) => {
14401
+ if (pointers.size > 0) {
14402
+ dragStartEvent.preventDefault();
14403
+ }
14404
+ };
14405
+
14382
14406
  // What the first event of the burst going on settled: a key let go of (or
14383
14407
  // pressed) halfway through must not hand a zoom to the page mid-gesture, and
14384
14408
  // a burst has no end but a silence.
@@ -14448,6 +14472,10 @@ const installPanZoom = (
14448
14472
  element.addEventListener("touchmove", preventTouchScroll, {
14449
14473
  passive: false,
14450
14474
  });
14475
+ // Without a pan, one pointer is whatever else reads it, its drag included.
14476
+ if (onPan) {
14477
+ element.addEventListener("dragstart", refuseNativeDrag);
14478
+ }
14451
14479
  if (onZoom) {
14452
14480
  element.addEventListener("wheel", onWheel, { passive: false });
14453
14481
  }
@@ -14459,6 +14487,7 @@ const installPanZoom = (
14459
14487
  element.removeEventListener("pointerdown", onPointerDown);
14460
14488
  element.removeEventListener("lostpointercapture", onLostPointerCapture);
14461
14489
  element.removeEventListener("touchmove", preventTouchScroll);
14490
+ element.removeEventListener("dragstart", refuseNativeDrag);
14462
14491
  element.removeEventListener("wheel", onWheel);
14463
14492
  window.removeEventListener("pointerdown", onPointerDownAway, true);
14464
14493
  element.removeAttribute(SURFACE_ATTRIBUTE);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/dom",
3
- "version": "0.17.94",
3
+ "version": "0.17.95",
4
4
  "type": "module",
5
5
  "description": "DOM utilities for writing frontend code",
6
6
  "repository": {