@testing-library/user-event 14.4.0 → 14.4.1

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 (81) hide show
  1. package/dist/cjs/clipboard/copy.js +2 -1
  2. package/dist/cjs/clipboard/cut.js +2 -1
  3. package/dist/cjs/clipboard/paste.js +4 -2
  4. package/dist/cjs/document/interceptor.js +4 -4
  5. package/dist/cjs/document/selection.js +4 -3
  6. package/dist/cjs/document/value.js +4 -2
  7. package/dist/cjs/event/behavior/keydown.js +6 -2
  8. package/dist/cjs/event/behavior/keypress.js +1 -1
  9. package/dist/cjs/event/behavior/keyup.js +2 -1
  10. package/dist/cjs/event/behavior/paste.js +2 -1
  11. package/dist/cjs/event/createEvent.js +35 -19
  12. package/dist/cjs/event/dispatchEvent.js +2 -1
  13. package/dist/cjs/keyboard/parseKeyDef.js +7 -4
  14. package/dist/cjs/pointer/index.js +10 -6
  15. package/dist/cjs/setup/setup.js +7 -4
  16. package/dist/cjs/system/index.js +4 -2
  17. package/dist/cjs/system/keyboard.js +25 -23
  18. package/dist/cjs/system/pointer/buttons.js +3 -1
  19. package/dist/cjs/system/pointer/device.js +3 -1
  20. package/dist/cjs/system/pointer/index.js +69 -61
  21. package/dist/cjs/system/pointer/mouse.js +53 -44
  22. package/dist/cjs/system/pointer/pointer.js +13 -12
  23. package/dist/cjs/utility/type.js +1 -1
  24. package/dist/cjs/utility/upload.js +6 -2
  25. package/dist/cjs/utils/dataTransfer/Clipboard.js +10 -6
  26. package/dist/cjs/utils/dataTransfer/DataTransfer.js +22 -19
  27. package/dist/cjs/utils/edit/input.js +2 -1
  28. package/dist/cjs/utils/edit/maxLength.js +2 -1
  29. package/dist/cjs/utils/edit/setFiles.js +4 -2
  30. package/dist/cjs/utils/focus/cursor.js +2 -1
  31. package/dist/cjs/utils/focus/focus.js +6 -3
  32. package/dist/cjs/utils/focus/getActiveElement.js +3 -2
  33. package/dist/cjs/utils/focus/resolveCaretPosition.js +3 -3
  34. package/dist/cjs/utils/focus/selectAll.js +5 -3
  35. package/dist/cjs/utils/focus/selection.js +23 -18
  36. package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -3
  37. package/dist/cjs/utils/misc/isDisabled.js +2 -1
  38. package/dist/cjs/utils/misc/isVisible.js +1 -1
  39. package/dist/cjs/utils/misc/level.js +5 -2
  40. package/dist/cjs/utils/pointer/cssPointerEvents.js +18 -11
  41. package/dist/esm/clipboard/copy.js +2 -1
  42. package/dist/esm/clipboard/cut.js +2 -1
  43. package/dist/esm/clipboard/paste.js +4 -2
  44. package/dist/esm/document/interceptor.js +4 -4
  45. package/dist/esm/document/selection.js +4 -3
  46. package/dist/esm/document/value.js +4 -2
  47. package/dist/esm/event/behavior/keydown.js +6 -2
  48. package/dist/esm/event/behavior/keypress.js +1 -1
  49. package/dist/esm/event/behavior/keyup.js +2 -1
  50. package/dist/esm/event/behavior/paste.js +2 -1
  51. package/dist/esm/event/createEvent.js +35 -19
  52. package/dist/esm/event/dispatchEvent.js +2 -1
  53. package/dist/esm/keyboard/parseKeyDef.js +7 -4
  54. package/dist/esm/pointer/index.js +10 -6
  55. package/dist/esm/setup/setup.js +7 -4
  56. package/dist/esm/system/index.js +4 -2
  57. package/dist/esm/system/keyboard.js +25 -23
  58. package/dist/esm/system/pointer/buttons.js +3 -1
  59. package/dist/esm/system/pointer/device.js +3 -1
  60. package/dist/esm/system/pointer/index.js +69 -61
  61. package/dist/esm/system/pointer/mouse.js +54 -45
  62. package/dist/esm/system/pointer/pointer.js +13 -12
  63. package/dist/esm/utility/type.js +1 -1
  64. package/dist/esm/utility/upload.js +6 -2
  65. package/dist/esm/utils/dataTransfer/Clipboard.js +10 -6
  66. package/dist/esm/utils/dataTransfer/DataTransfer.js +22 -19
  67. package/dist/esm/utils/edit/input.js +2 -1
  68. package/dist/esm/utils/edit/maxLength.js +2 -1
  69. package/dist/esm/utils/edit/setFiles.js +4 -2
  70. package/dist/esm/utils/focus/cursor.js +2 -1
  71. package/dist/esm/utils/focus/focus.js +6 -3
  72. package/dist/esm/utils/focus/getActiveElement.js +3 -2
  73. package/dist/esm/utils/focus/resolveCaretPosition.js +3 -3
  74. package/dist/esm/utils/focus/selectAll.js +5 -3
  75. package/dist/esm/utils/focus/selection.js +23 -18
  76. package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -3
  77. package/dist/esm/utils/misc/isDisabled.js +2 -1
  78. package/dist/esm/utils/misc/isVisible.js +1 -1
  79. package/dist/esm/utils/misc/level.js +5 -2
  80. package/dist/esm/utils/pointer/cssPointerEvents.js +18 -11
  81. package/package.json +3 -3
@@ -18,11 +18,12 @@ import { wrapAsync } from './wrapAsync.js';
18
18
 
19
19
  function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
20
20
  const document = getDocument(options, node, defaults);
21
+ var _system;
21
22
  return {
22
23
  ...defaults,
23
24
  ...options,
24
25
  document,
25
- system: options.system ?? new System()
26
+ system: (_system = options.system) !== null && _system !== void 0 ? _system : new System()
26
27
  };
27
28
  }
28
29
  /**
@@ -31,7 +32,8 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
31
32
  */ function setupMain(options = {}) {
32
33
  const config = createConfig(options);
33
34
  prepareDocument(config.document);
34
- const view = config.document.defaultView ?? /* istanbul ignore next */ globalThis.window;
35
+ var _defaultView;
36
+ const view = (_defaultView = config.document.defaultView) !== null && _defaultView !== void 0 ? _defaultView : /* istanbul ignore next */ globalThis.window;
35
37
  attachClipboardStubToView(view);
36
38
  return doSetup(config);
37
39
  }
@@ -40,7 +42,7 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
40
42
  */ function setupDirect({ keyboardState , pointerState , ...options } = {}, node) {
41
43
  const config = createConfig({
42
44
  ...options,
43
- system: pointerState ?? keyboardState
45
+ system: pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState
44
46
  }, defaultOptionsDirect, node);
45
47
  prepareDocument(config.document);
46
48
  return {
@@ -84,7 +86,8 @@ function doSetup(config) {
84
86
  };
85
87
  }
86
88
  function getDocument(options, node, defaults) {
87
- return (options.document ?? (node && getDocumentFromNode(node))) ?? defaults.document;
89
+ var _document, ref;
90
+ return (ref = (_document = options.document) !== null && _document !== void 0 ? _document : node && getDocumentFromNode(node)) !== null && ref !== void 0 ? ref : defaults.document;
88
91
  }
89
92
 
90
93
  export { createConfig, setupDirect, setupMain, setupSub };
@@ -4,8 +4,6 @@ import { PointerHost } from './pointer/index.js';
4
4
  /**
5
5
  * @internal Do not create/alter this by yourself as this type might be subject to changes.
6
6
  */ class System {
7
- keyboard = new KeyboardHost(this);
8
- pointer = new PointerHost(this);
9
7
  getUIEventModifiers() {
10
8
  return {
11
9
  altKey: this.keyboard.modifiers.Alt,
@@ -22,6 +20,10 @@ import { PointerHost } from './pointer/index.js';
22
20
  modifierSymbolLock: this.keyboard.modifiers.SymbolLock
23
21
  };
24
22
  }
23
+ constructor(){
24
+ this.keyboard = new KeyboardHost(this);
25
+ this.pointer = new PointerHost(this);
26
+ }
25
27
  }
26
28
 
27
29
  export { System };
@@ -10,6 +10,7 @@ import '../utils/keyDef/readNextDescriptor.js';
10
10
  import '../utils/misc/level.js';
11
11
  import '../options.js';
12
12
 
13
+ var _pressed, _code, _code1;
13
14
  var DOM_KEY_LOCATION;
14
15
  (function(DOM_KEY_LOCATION) {
15
16
  DOM_KEY_LOCATION[DOM_KEY_LOCATION["STANDARD"] = 0] = "STANDARD";
@@ -40,27 +41,6 @@ function isModifierLock(key) {
40
41
  return modifierLocks.includes(key);
41
42
  }
42
43
  class KeyboardHost {
43
- constructor(system){
44
- this.system = system;
45
- }
46
- modifiers = {
47
- Alt: false,
48
- AltGraph: false,
49
- CapsLock: false,
50
- Control: false,
51
- Fn: false,
52
- FnLock: false,
53
- Meta: false,
54
- NumLock: false,
55
- ScrollLock: false,
56
- Shift: false,
57
- Symbol: false,
58
- SymbolLock: false
59
- };
60
- pressed = {};
61
- carryChar = '';
62
- lastKeydownTarget = undefined;
63
- modifierLockStart = {};
64
44
  isKeyPressed(keyDef) {
65
45
  return !!this.pressed[String(keyDef.code)];
66
46
  }
@@ -72,7 +52,8 @@ class KeyboardHost {
72
52
  const code = String(keyDef.code);
73
53
  const target = getActiveElementOrBody(config.document);
74
54
  this.setKeydownTarget(target);
75
- this.pressed[code] ??= {
55
+ var ref;
56
+ (ref = (_pressed = this.pressed)[_code = code]) !== null && ref !== void 0 ? ref : _pressed[_code] = {
76
57
  keyDef,
77
58
  unpreventedDefault: false
78
59
  };
@@ -87,7 +68,7 @@ class KeyboardHost {
87
68
  this.modifiers[key] = true;
88
69
  this.modifierLockStart[key] = true;
89
70
  }
90
- this.pressed[code].unpreventedDefault ||= unprevented;
71
+ (_code1 = this.pressed[code]).unpreventedDefault || (_code1.unpreventedDefault = unprevented);
91
72
  if (unprevented && this.hasKeyPress(key)) {
92
73
  dispatchUIEvent(config, getActiveElementOrBody(config.document), 'keypress', {
93
74
  key,
@@ -126,6 +107,27 @@ class KeyboardHost {
126
107
  hasKeyPress(key) {
127
108
  return (key.length === 1 || key === 'Enter') && !this.modifiers.Control && !this.modifiers.Alt;
128
109
  }
110
+ constructor(system){
111
+ this.modifiers = {
112
+ Alt: false,
113
+ AltGraph: false,
114
+ CapsLock: false,
115
+ Control: false,
116
+ Fn: false,
117
+ FnLock: false,
118
+ Meta: false,
119
+ NumLock: false,
120
+ ScrollLock: false,
121
+ Shift: false,
122
+ Symbol: false,
123
+ SymbolLock: false
124
+ };
125
+ this.pressed = {};
126
+ this.carryChar = '';
127
+ this.lastKeydownTarget = undefined;
128
+ this.modifierLockStart = {};
129
+ this.system = system;
130
+ }
129
131
  }
130
132
 
131
133
  export { DOM_KEY_LOCATION, KeyboardHost };
@@ -1,5 +1,4 @@
1
1
  class Buttons {
2
- pressed = {};
3
2
  getButtons() {
4
3
  let v = 0;
5
4
  for (const button of Object.keys(this.pressed)){
@@ -31,6 +30,9 @@ class Buttons {
31
30
  }
32
31
  return undefined;
33
32
  }
33
+ constructor(){
34
+ this.pressed = {};
35
+ }
34
36
  }
35
37
  const MouseButton = {
36
38
  primary: 0,
@@ -1,5 +1,4 @@
1
1
  class Device {
2
- pressedKeys = new Set();
3
2
  get countPressed() {
4
3
  return this.pressedKeys.size;
5
4
  }
@@ -12,6 +11,9 @@ class Device {
12
11
  removePressed(keyDef) {
13
12
  return this.pressedKeys.delete(keyDef.name);
14
13
  }
14
+ constructor(){
15
+ this.pressedKeys = new Set();
16
+ }
15
17
  }
16
18
 
17
19
  export { Device };
@@ -3,54 +3,8 @@ import { Device } from './device.js';
3
3
  import { Mouse } from './mouse.js';
4
4
  import { Pointer } from './pointer.js';
5
5
 
6
+ var _registry, _k;
6
7
  class PointerHost {
7
- constructor(system){
8
- this.system = system;
9
- this.buttons = new Buttons();
10
- this.mouse = new Mouse();
11
- }
12
- devices = new class {
13
- registry = {};
14
- get(k) {
15
- this.registry[k] ??= new Device();
16
- return this.registry[k];
17
- }
18
- }();
19
- pointers = new class {
20
- registry = {
21
- mouse: new Pointer({
22
- pointerId: 1,
23
- pointerType: 'mouse',
24
- isPrimary: true
25
- })
26
- };
27
- nextId = 2;
28
- new(pointerName, keyDef) {
29
- const isPrimary = keyDef.pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
30
- if (!isPrimary) {
31
- Object.values(this.registry).forEach((p)=>{
32
- if (p.pointerType === keyDef.pointerType && !p.isCancelled) {
33
- p.isMultitouch = true;
34
- }
35
- });
36
- }
37
- this.registry[pointerName] = new Pointer({
38
- pointerId: this.nextId++,
39
- pointerType: keyDef.pointerType,
40
- isPrimary
41
- });
42
- return this.registry[pointerName];
43
- }
44
- get(pointerName) {
45
- if (!this.has(pointerName)) {
46
- throw new Error(`Trying to access pointer "${pointerName}" which does not exist.`);
47
- }
48
- return this.registry[pointerName];
49
- }
50
- has(pointerName) {
51
- return pointerName in this.registry;
52
- }
53
- }();
54
8
  isKeyPressed(keyDef) {
55
9
  return this.devices.get(keyDef.pointerType).isPressed(keyDef);
56
10
  }
@@ -77,12 +31,12 @@ class PointerHost {
77
31
  // the order in which they interweave/follow on a user interaction depends on the implementation.
78
32
  const pointermove = pointer.move(config, position);
79
33
  const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(config, position);
80
- pointermove?.leave();
81
- mousemove?.leave();
82
- pointermove?.enter();
83
- mousemove?.enter();
84
- pointermove?.move();
85
- mousemove?.move();
34
+ pointermove === null || pointermove === void 0 ? void 0 : pointermove.leave();
35
+ mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave();
36
+ pointermove === null || pointermove === void 0 ? void 0 : pointermove.enter();
37
+ mousemove === null || mousemove === void 0 ? void 0 : mousemove.enter();
38
+ pointermove === null || pointermove === void 0 ? void 0 : pointermove.move();
39
+ mousemove === null || mousemove === void 0 ? void 0 : mousemove.move();
86
40
  }
87
41
  async release(config, keyDef, position) {
88
42
  const device = this.devices.get(keyDef.pointerType);
@@ -103,16 +57,16 @@ class PointerHost {
103
57
  if (!pointer.isPrevented) {
104
58
  if (pointer.pointerType === 'touch' && !pointer.isMultitouch) {
105
59
  const mousemove = this.mouse.move(config, pointer.position);
106
- mousemove?.leave();
107
- mousemove?.enter();
108
- mousemove?.move();
60
+ mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave();
61
+ mousemove === null || mousemove === void 0 ? void 0 : mousemove.enter();
62
+ mousemove === null || mousemove === void 0 ? void 0 : mousemove.move();
109
63
  this.mouse.down(config, keyDef, pointer);
110
64
  }
111
65
  if (!pointer.isMultitouch) {
112
66
  const mousemove1 = this.mouse.move(config, pointer.position);
113
- mousemove1?.leave();
114
- mousemove1?.enter();
115
- mousemove1?.move();
67
+ mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.leave();
68
+ mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.enter();
69
+ mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.move();
116
70
  this.mouse.up(config, keyDef, pointer);
117
71
  }
118
72
  }
@@ -127,15 +81,69 @@ class PointerHost {
127
81
  this.mouse.resetClickCount();
128
82
  }
129
83
  getMouseTarget(config) {
130
- return this.mouse.position.target ?? config.document.body;
84
+ var _target;
85
+ return (_target = this.mouse.position.target) !== null && _target !== void 0 ? _target : config.document.body;
131
86
  }
132
87
  setMousePosition(position) {
133
88
  this.mouse.position = position;
134
89
  this.pointers.get('mouse').position = position;
135
90
  }
91
+ constructor(system){
92
+ this.devices = new class {
93
+ get(k) {
94
+ var ref;
95
+ (ref = (_registry = this.registry)[_k = k]) !== null && ref !== void 0 ? ref : _registry[_k] = new Device();
96
+ return this.registry[k];
97
+ }
98
+ constructor(){
99
+ this.registry = {};
100
+ }
101
+ }();
102
+ this.pointers = new class {
103
+ new(pointerName, keyDef) {
104
+ const isPrimary = keyDef.pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
105
+ if (!isPrimary) {
106
+ Object.values(this.registry).forEach((p)=>{
107
+ if (p.pointerType === keyDef.pointerType && !p.isCancelled) {
108
+ p.isMultitouch = true;
109
+ }
110
+ });
111
+ }
112
+ this.registry[pointerName] = new Pointer({
113
+ pointerId: this.nextId++,
114
+ pointerType: keyDef.pointerType,
115
+ isPrimary
116
+ });
117
+ return this.registry[pointerName];
118
+ }
119
+ get(pointerName) {
120
+ if (!this.has(pointerName)) {
121
+ throw new Error(`Trying to access pointer "${pointerName}" which does not exist.`);
122
+ }
123
+ return this.registry[pointerName];
124
+ }
125
+ has(pointerName) {
126
+ return pointerName in this.registry;
127
+ }
128
+ constructor(){
129
+ this.registry = {
130
+ mouse: new Pointer({
131
+ pointerId: 1,
132
+ pointerType: 'mouse',
133
+ isPrimary: true
134
+ })
135
+ };
136
+ this.nextId = 2;
137
+ }
138
+ }();
139
+ this.system = system;
140
+ this.buttons = new Buttons();
141
+ this.mouse = new Mouse();
142
+ }
136
143
  }
137
144
  function isDifferentPointerPosition(positionA, positionB) {
138
- return positionA.target !== positionB.target || positionA.coords?.x !== positionB.coords?.y || positionA.coords?.y !== positionB.coords?.y || positionA.caret?.node !== positionB.caret?.node || positionA.caret?.offset !== positionB.caret?.offset;
145
+ var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
146
+ return positionA.target !== positionB.target || ((ref = positionA.coords) === null || ref === void 0 ? void 0 : ref.x) !== ((ref1 = positionB.coords) === null || ref1 === void 0 ? void 0 : ref1.y) || ((ref2 = positionA.coords) === null || ref2 === void 0 ? void 0 : ref2.y) !== ((ref3 = positionB.coords) === null || ref3 === void 0 ? void 0 : ref3.y) || ((ref4 = positionA.caret) === null || ref4 === void 0 ? void 0 : ref4.node) !== ((ref5 = positionB.caret) === null || ref5 === void 0 ? void 0 : ref5.node) || ((ref6 = positionA.caret) === null || ref6 === void 0 ? void 0 : ref6.offset) !== ((ref7 = positionB.caret) === null || ref7 === void 0 ? void 0 : ref7.offset);
139
147
  }
140
148
 
141
149
  export { PointerHost, isDifferentPointerPosition };
@@ -13,50 +13,11 @@ import { getTreeDiff } from '../../utils/misc/getTreeDiff.js';
13
13
  import '../../utils/misc/level.js';
14
14
  import '../../options.js';
15
15
  import { isDifferentPointerPosition } from './index.js';
16
- import { Buttons, getMouseEventButton } from './buttons.js';
16
+ import { getMouseEventButton, Buttons } from './buttons.js';
17
17
 
18
18
  /**
19
19
  * This object is the single "virtual" mouse that might be controlled by multiple different pointer devices.
20
20
  */ class Mouse {
21
- position = {};
22
- buttons = new Buttons();
23
- buttonDownTarget = {};
24
- // According to spec the `detail` on click events should be the number
25
- // of *consecutive* clicks with a specific button.
26
- // On `mousedown` and `mouseup` it should be this number increased by one.
27
- // But the browsers don't implement it this way.
28
- // If another button is pressed,
29
- // in Webkit: the `mouseup` on the previously pressed button has `detail: 0` and no `click`/`auxclick`.
30
- // in Gecko: the `mouseup` and click events have the same detail as the `mousedown`.
31
- // If there is a delay while a button is pressed,
32
- // the `mouseup` and `click` are normal, but a following `mousedown` starts a new click count.
33
- // We'll follow the minimal implementation of Webkit.
34
- clickCount = new class {
35
- down = {};
36
- count = {};
37
- incOnClick(button) {
38
- const current = this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
39
- this.count = this.count[button] === undefined ? {} : {
40
- [button]: Number(this.count[button]) + 1
41
- };
42
- return current;
43
- }
44
- getOnDown(button) {
45
- this.down = {
46
- [button]: this.count[button] ?? 0
47
- };
48
- this.count = {
49
- [button]: this.count[button] ?? 0
50
- };
51
- return Number(this.count[button]) + 1;
52
- }
53
- getOnUp(button) {
54
- return this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
55
- }
56
- reset() {
57
- this.count = {};
58
- }
59
- }();
60
21
  move(config, position) {
61
22
  const prevPosition = this.position;
62
23
  const prevTarget = this.getTarget(config);
@@ -151,32 +112,80 @@ import { Buttons, getMouseEventButton } from './buttons.js';
151
112
  return init;
152
113
  }
153
114
  getTarget(config) {
154
- return this.position.target ?? config.document.body;
115
+ var _target;
116
+ return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body;
155
117
  }
156
118
  startSelecting(config, clickCount) {
119
+ var ref, ref1;
157
120
  // TODO: support extending range (shift)
158
121
  this.selecting = setSelectionPerMouseDown({
159
122
  document: config.document,
160
123
  target: this.getTarget(config),
161
- node: this.position.caret?.node,
162
- offset: this.position.caret?.offset,
124
+ node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node,
125
+ offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset,
163
126
  clickCount
164
127
  });
165
128
  }
166
129
  modifySelecting(config) {
130
+ var ref, ref1;
167
131
  if (!this.selecting) {
168
132
  return;
169
133
  }
170
134
  modifySelectionPerMouseMove(this.selecting, {
171
135
  document: config.document,
172
136
  target: this.getTarget(config),
173
- node: this.position.caret?.node,
174
- offset: this.position.caret?.offset
137
+ node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node,
138
+ offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset
175
139
  });
176
140
  }
177
141
  endSelecting() {
178
142
  this.selecting = undefined;
179
143
  }
144
+ constructor(){
145
+ this.position = {};
146
+ this.buttons = new Buttons();
147
+ this.buttonDownTarget = {};
148
+ // According to spec the `detail` on click events should be the number
149
+ // of *consecutive* clicks with a specific button.
150
+ // On `mousedown` and `mouseup` it should be this number increased by one.
151
+ // But the browsers don't implement it this way.
152
+ // If another button is pressed,
153
+ // in Webkit: the `mouseup` on the previously pressed button has `detail: 0` and no `click`/`auxclick`.
154
+ // in Gecko: the `mouseup` and click events have the same detail as the `mousedown`.
155
+ // If there is a delay while a button is pressed,
156
+ // the `mouseup` and `click` are normal, but a following `mousedown` starts a new click count.
157
+ // We'll follow the minimal implementation of Webkit.
158
+ this.clickCount = new class {
159
+ incOnClick(button) {
160
+ const current = this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
161
+ this.count = this.count[button] === undefined ? {} : {
162
+ [button]: Number(this.count[button]) + 1
163
+ };
164
+ return current;
165
+ }
166
+ getOnDown(button) {
167
+ var _button;
168
+ this.down = {
169
+ [button]: (_button = this.count[button]) !== null && _button !== void 0 ? _button : 0
170
+ };
171
+ var _button1;
172
+ this.count = {
173
+ [button]: (_button1 = this.count[button]) !== null && _button1 !== void 0 ? _button1 : 0
174
+ };
175
+ return Number(this.count[button]) + 1;
176
+ }
177
+ getOnUp(button) {
178
+ return this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
179
+ }
180
+ reset() {
181
+ this.count = {};
182
+ }
183
+ constructor(){
184
+ this.down = {};
185
+ this.count = {};
186
+ }
187
+ }();
188
+ }
180
189
  }
181
190
 
182
191
  export { Mouse };
@@ -12,17 +12,6 @@ import { assertPointerEvents, hasPointerEvents } from '../../utils/pointer/cssPo
12
12
  import { isDifferentPointerPosition } from './index.js';
13
13
 
14
14
  class Pointer {
15
- constructor({ pointerId , pointerType , isPrimary }){
16
- this.pointerId = pointerId;
17
- this.pointerType = pointerType;
18
- this.isPrimary = isPrimary;
19
- this.isMultitouch = !isPrimary;
20
- }
21
- isMultitouch = false;
22
- isCancelled = false;
23
- isDown = false;
24
- isPrevented = false;
25
- position = {};
26
15
  init(config, position) {
27
16
  this.position = position;
28
17
  const target = this.getTarget(config);
@@ -95,7 +84,8 @@ class Pointer {
95
84
  this.isCancelled = true;
96
85
  }
97
86
  getTarget(config) {
98
- return this.position.target ?? config.document.body;
87
+ var _target;
88
+ return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body;
99
89
  }
100
90
  getEventInit() {
101
91
  return {
@@ -105,6 +95,17 @@ class Pointer {
105
95
  isPrimary: this.isPrimary
106
96
  };
107
97
  }
98
+ constructor({ pointerId , pointerType , isPrimary }){
99
+ this.isMultitouch = false;
100
+ this.isCancelled = false;
101
+ this.isDown = false;
102
+ this.isPrevented = false;
103
+ this.position = {};
104
+ this.pointerId = pointerId;
105
+ this.pointerType = pointerType;
106
+ this.isPrimary = isPrimary;
107
+ this.isMultitouch = !isPrimary;
108
+ }
108
109
  }
109
110
 
110
111
  export { Pointer };
@@ -26,7 +26,7 @@ async function type(element, text, { skipClick =this[Config].skipClick , skipAut
26
26
  await this.click(element);
27
27
  }
28
28
  if (initialSelectionStart !== undefined) {
29
- setSelectionRange(element, initialSelectionStart, initialSelectionEnd ?? initialSelectionStart);
29
+ setSelectionRange(element, initialSelectionStart, initialSelectionEnd !== null && initialSelectionEnd !== void 0 ? initialSelectionEnd : initialSelectionStart);
30
30
  }
31
31
  await this.keyboard(text);
32
32
  if (!skipAutoClose) {
@@ -26,15 +26,19 @@ async function upload(element, fileOrFiles) {
26
26
  if (!input || !isElementType(input, 'input', {
27
27
  type: 'file'
28
28
  })) {
29
- throw new TypeError(`The ${input === element ? 'given' : 'associated'} ${input?.tagName} element does not accept file uploads`);
29
+ throw new TypeError(`The ${input === element ? 'given' : 'associated'} ${input === null || input === void 0 ? void 0 : input.tagName} element does not accept file uploads`);
30
30
  }
31
31
  if (isDisabled(element)) return;
32
32
  const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [
33
33
  fileOrFiles
34
34
  ]).filter((file)=>!this[Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1);
35
35
  const fileDialog = ()=>{
36
+ var ref;
36
37
  // do not fire an input event if the file selection does not change
37
- if (files.length === input.files?.length && files.every((f, i)=>f === input.files?.item(i))) {
38
+ if (files.length === ((ref = input.files) === null || ref === void 0 ? void 0 : ref.length) && files.every((f, i)=>{
39
+ var ref;
40
+ return f === ((ref = input.files) === null || ref === void 0 ? void 0 : ref.item(i));
41
+ })) {
38
42
  return;
39
43
  }
40
44
  setFiles(input, createFileList(getWindow(element), files));
@@ -30,9 +30,6 @@ function createClipboardItem(window, ...blobs) {
30
30
  return new window.ClipboardItem(dataMap);
31
31
  }
32
32
  return new class ClipboardItem {
33
- constructor(d){
34
- this.data = d;
35
- }
36
33
  get types() {
37
34
  return Array.from(Object.keys(this.data));
38
35
  }
@@ -47,12 +44,14 @@ function createClipboardItem(window, ...blobs) {
47
44
  type
48
45
  });
49
46
  }
47
+ constructor(d){
48
+ this.data = d;
49
+ }
50
50
  }(dataMap);
51
51
  }
52
52
  const ClipboardStubControl = Symbol('Manage ClipboardSub');
53
53
  function createClipboardStub(window, control) {
54
54
  return Object.assign(new class Clipboard extends window.EventTarget {
55
- items = [];
56
55
  async read() {
57
56
  return Array.from(this.items);
58
57
  }
@@ -74,12 +73,17 @@ function createClipboardStub(window, control) {
74
73
  createClipboardItem(window, text)
75
74
  ];
76
75
  }
76
+ constructor(...args){
77
+ super(...args);
78
+ this.items = [];
79
+ }
77
80
  }(), {
78
81
  [ClipboardStubControl]: control
79
82
  });
80
83
  }
81
84
  function isClipboardStub(clipboard) {
82
- return !!clipboard?.[ClipboardStubControl];
85
+ var ref;
86
+ return !!((ref = clipboard) === null || ref === void 0 ? void 0 : ref[ClipboardStubControl]);
83
87
  }
84
88
  function attachClipboardStubToView(window) {
85
89
  if (isClipboardStub(window.navigator.clipboard)) {
@@ -121,7 +125,7 @@ function detachClipboardStubFromView(window) {
121
125
  }
122
126
  async function readDataTransferFromClipboard(document) {
123
127
  const window = document.defaultView;
124
- const clipboard = window?.navigator.clipboard;
128
+ const clipboard = window === null || window === void 0 ? void 0 : window.navigator.clipboard;
125
129
  const items = clipboard && await clipboard.read();
126
130
  if (!items) {
127
131
  throw new Error('The Clipboard API is unavailable.');