@jsenv/dom 0.17.67 → 0.17.68

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 +25 -2
  2. package/package.json +1 -1
package/dist/jsenv_dom.js CHANGED
@@ -319,11 +319,14 @@ const chainEvent = (customEvent, parentEvent) => {
319
319
  * which one WAS used — a tap brings the on-screen keyboard up, the trackpad
320
320
  * next to it does not.
321
321
  *
322
- * Three readings, because no single one covers every path from a finger to an
322
+ * Four readings, because no single one covers every path from a finger to an
323
323
  * event:
324
324
  * - a touch* event says it outright;
325
325
  * - `pointerType` says it on a PointerEvent, which "click" also is in some
326
326
  * engines and not in others — hence not the only reading;
327
+ * - the click WebKit dispatches for a tap is a PointerEvent whose `pointerType`
328
+ * says "mouse" while its `pointerId` is the finger's: the press last seen
329
+ * down with that id answers for it (see lastPress below);
327
330
  * - `sourceCapabilities.firesTouchEvents` is what is left for the compatibility
328
331
  * mouse events a tap synthesizes, where nothing else remembers the finger.
329
332
  * Absent outside Chromium, where it costs nothing: the readings above have
@@ -339,10 +342,30 @@ const isTouchDrivenEvent = (event) => {
339
342
  // "" on a pointer event the engine could not attribute — not an answer, so
340
343
  // it falls through to the last reading rather than being read as "not touch".
341
344
  if (event.pointerType) {
342
- return event.pointerType === "touch";
345
+ if (event.pointerType === "touch") {
346
+ return true;
347
+ }
348
+ if (lastPress && event.pointerId === lastPress.pointerId) {
349
+ return lastPress.pointerType === "touch";
350
+ }
351
+ return false;
343
352
  }
344
353
  return event.sourceCapabilities?.firesTouchEvents === true;
345
354
  };
355
+ // The press behind the next click: a click follows the pointerup of its own
356
+ // press, and no other press comes between the two. Recorded on window in
357
+ // capture so that nothing lower can hide a press from it.
358
+ let lastPress = null;
359
+ window.addEventListener(
360
+ "pointerdown",
361
+ (pointerdownEvent) => {
362
+ lastPress = {
363
+ pointerId: pointerdownEvent.pointerId,
364
+ pointerType: pointerdownEvent.pointerType,
365
+ };
366
+ },
367
+ { capture: true, passive: true },
368
+ );
346
369
 
347
370
  /**
348
371
  * Whether `event` is a click a pointer press produced, as opposed to one
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/dom",
3
- "version": "0.17.67",
3
+ "version": "0.17.68",
4
4
  "type": "module",
5
5
  "description": "DOM utilities for writing frontend code",
6
6
  "repository": {