@testing-library/user-event 14.0.4 → 14.2.0

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.
package/dist/index.cjs CHANGED
@@ -156,8 +156,8 @@ var DataTransferStub = class {
156
156
  this.files = createFileList([]);
157
157
  }
158
158
  getData(format) {
159
- var _a3;
160
- const match = (_a3 = this.items.find(getTypeMatcher(format, true))) != null ? _a3 : this.items.find(getTypeMatcher(format, false));
159
+ var _a;
160
+ const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
161
161
  let text = "";
162
162
  match == null ? void 0 : match.getAsString((t) => {
163
163
  text = t;
@@ -195,12 +195,12 @@ var DataTransferStub = class {
195
195
  setDragImage() {
196
196
  }
197
197
  };
198
- function createDataTransfer(window2, files = []) {
199
- const dt = typeof window2.DataTransfer === "undefined" ? new DataTransferStub() : new window2.DataTransfer();
198
+ function createDataTransfer(window, files = []) {
199
+ const dt = typeof window.DataTransfer === "undefined" ? new DataTransferStub() : new window.DataTransfer();
200
200
  Object.defineProperty(dt, "files", { get: () => createFileList(files) });
201
201
  return dt;
202
202
  }
203
- function getBlobFromDataTransferItem(window2, item) {
203
+ function getBlobFromDataTransferItem(window, item) {
204
204
  if (item.kind === "file") {
205
205
  return item.getAsFile();
206
206
  }
@@ -208,7 +208,7 @@ function getBlobFromDataTransferItem(window2, item) {
208
208
  item.getAsString((s) => {
209
209
  data = s;
210
210
  });
211
- return new window2.Blob([data], { type: item.type });
211
+ return new window.Blob([data], { type: item.type });
212
212
  }
213
213
 
214
214
  // src/utils/misc/getWindow.ts
@@ -218,85 +218,78 @@ function getWindow(node) {
218
218
  }
219
219
 
220
220
  // src/utils/dataTransfer/Clipboard.ts
221
- var Window = Symbol("Window reference");
222
- var _a;
223
- var ClipboardItemStub = class {
224
- constructor(data) {
225
- this[_a] = window;
226
- this.data = data;
227
- }
228
- get types() {
229
- return Array.from(Object.keys(this.data));
221
+ function createClipboardItem(window, ...blobs) {
222
+ const dataMap = Object.fromEntries(blobs.map((b) => [
223
+ typeof b === "string" ? "text/plain" : b.type,
224
+ Promise.resolve(b)
225
+ ]));
226
+ if (typeof window.ClipboardItem !== "undefined") {
227
+ return new window.ClipboardItem(dataMap);
230
228
  }
231
- async getType(type3) {
232
- const data = await this.data[type3];
233
- if (!data) {
234
- throw new Error(`${type3} is not one of the available MIME types on this item.`);
229
+ return new class ClipboardItem {
230
+ constructor(d) {
231
+ this.data = d;
235
232
  }
236
- return data instanceof this[Window].Blob ? data : new this[Window].Blob([data], { type: type3 });
237
- }
238
- };
239
- _a = Window;
233
+ get types() {
234
+ return Array.from(Object.keys(this.data));
235
+ }
236
+ async getType(type3) {
237
+ const value = await this.data[type3];
238
+ if (!value) {
239
+ throw new Error(`${type3} is not one of the available MIME types on this item.`);
240
+ }
241
+ return value instanceof window.Blob ? value : new window.Blob([value], { type: type3 });
242
+ }
243
+ }(dataMap);
244
+ }
240
245
  var ClipboardStubControl = Symbol("Manage ClipboardSub");
241
- var _a2;
242
- var ClipboardStub = class extends window.EventTarget {
243
- constructor() {
244
- super(...arguments);
245
- this.items = [];
246
- this[_a2] = window;
247
- }
248
- async read() {
249
- return Array.from(this.items);
250
- }
251
- async readText() {
252
- let text = "";
253
- for (const item of this.items) {
254
- const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
255
- if (type3) {
256
- text += await item.getType(type3).then((b) => readBlobText(b, this[Window].FileReader));
246
+ function createClipboardStub(window) {
247
+ var _a;
248
+ return new (_a = class extends window.EventTarget {
249
+ constructor() {
250
+ super(...arguments);
251
+ this.items = [];
252
+ }
253
+ async read() {
254
+ return Array.from(this.items);
255
+ }
256
+ async readText() {
257
+ let text = "";
258
+ for (const item of this.items) {
259
+ const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
260
+ if (type3) {
261
+ text += await item.getType(type3).then((b) => readBlobText(b, window.FileReader));
262
+ }
257
263
  }
264
+ return text;
258
265
  }
259
- return text;
260
- }
261
- async write(data) {
262
- this.items = data;
263
- }
264
- async writeText(text) {
265
- this.items = [createClipboardItem(this[Window], text)];
266
- }
267
- };
268
- _a2 = Window, ClipboardStubControl;
269
- function createClipboardItem(window2, ...blobs) {
270
- const data = Object.fromEntries(blobs.map((b) => [
271
- typeof b === "string" ? "text/plain" : b.type,
272
- Promise.resolve(b)
273
- ]));
274
- if (typeof window2.ClipboardItem === "undefined") {
275
- const item = new ClipboardItemStub(data);
276
- item[Window] = window2;
277
- return item;
278
- } else {
279
- return new window2.ClipboardItem(data);
280
- }
266
+ async write(data) {
267
+ this.items = data;
268
+ }
269
+ async writeText(text) {
270
+ this.items = [createClipboardItem(window, text)];
271
+ }
272
+ }, ClipboardStubControl, _a)();
273
+ }
274
+ function isClipboardStub(clipboard) {
275
+ return !!(clipboard == null ? void 0 : clipboard[ClipboardStubControl]);
281
276
  }
282
- function attachClipboardStubToView(window2) {
283
- if (window2.navigator.clipboard instanceof ClipboardStub) {
284
- return window2.navigator.clipboard[ClipboardStubControl];
277
+ function attachClipboardStubToView(window) {
278
+ if (isClipboardStub(window.navigator.clipboard)) {
279
+ return window.navigator.clipboard[ClipboardStubControl];
285
280
  }
286
- const realClipboard = Object.getOwnPropertyDescriptor(window2.navigator, "clipboard");
287
- let stub = new ClipboardStub();
288
- stub[Window] = window2;
281
+ const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, "clipboard");
282
+ let stub = createClipboardStub(window);
289
283
  const control = {
290
284
  resetClipboardStub: () => {
291
- stub = new ClipboardStub();
292
- stub[Window] = window2;
285
+ stub = createClipboardStub(window);
293
286
  stub[ClipboardStubControl] = control;
294
287
  },
295
288
  detachClipboardStub: () => {
296
289
  if (realClipboard) {
297
- Object.defineProperty(window2.navigator, "clipboard", realClipboard);
290
+ Object.defineProperty(window.navigator, "clipboard", realClipboard);
298
291
  } else {
299
- Object.defineProperty(window2.navigator, "clipboard", {
292
+ Object.defineProperty(window.navigator, "clipboard", {
300
293
  value: void 0,
301
294
  configurable: true
302
295
  });
@@ -304,56 +297,56 @@ function attachClipboardStubToView(window2) {
304
297
  }
305
298
  };
306
299
  stub[ClipboardStubControl] = control;
307
- Object.defineProperty(window2.navigator, "clipboard", {
300
+ Object.defineProperty(window.navigator, "clipboard", {
308
301
  get: () => stub,
309
302
  configurable: true
310
303
  });
311
304
  return stub[ClipboardStubControl];
312
305
  }
313
- function resetClipboardStubOnView(window2) {
314
- if (window2.navigator.clipboard instanceof ClipboardStub) {
315
- window2.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
306
+ function resetClipboardStubOnView(window) {
307
+ if (isClipboardStub(window.navigator.clipboard)) {
308
+ window.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
316
309
  }
317
310
  }
318
- function detachClipboardStubFromView(window2) {
319
- if (window2.navigator.clipboard instanceof ClipboardStub) {
320
- window2.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
311
+ function detachClipboardStubFromView(window) {
312
+ if (isClipboardStub(window.navigator.clipboard)) {
313
+ window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
321
314
  }
322
315
  }
323
- async function readDataTransferFromClipboard(document2) {
324
- const window2 = document2.defaultView;
325
- const clipboard = window2 == null ? void 0 : window2.navigator.clipboard;
316
+ async function readDataTransferFromClipboard(document) {
317
+ const window = document.defaultView;
318
+ const clipboard = window == null ? void 0 : window.navigator.clipboard;
326
319
  const items = clipboard && await clipboard.read();
327
320
  if (!items) {
328
321
  throw new Error("The Clipboard API is unavailable.");
329
322
  }
330
- const dt = createDataTransfer(window2);
323
+ const dt = createDataTransfer(window);
331
324
  for (const item of items) {
332
325
  for (const type3 of item.types) {
333
- dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b, window2.FileReader)));
326
+ dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b, window.FileReader)));
334
327
  }
335
328
  }
336
329
  return dt;
337
330
  }
338
- async function writeDataTransferToClipboard(document2, clipboardData) {
339
- const window2 = getWindow(document2);
340
- const clipboard = window2.navigator.clipboard;
331
+ async function writeDataTransferToClipboard(document, clipboardData) {
332
+ const window = getWindow(document);
333
+ const clipboard = window.navigator.clipboard;
341
334
  const items = [];
342
335
  for (let i = 0; i < clipboardData.items.length; i++) {
343
336
  const dtItem = clipboardData.items[i];
344
- const blob = getBlobFromDataTransferItem(window2, dtItem);
345
- items.push(createClipboardItem(window2, blob));
337
+ const blob = getBlobFromDataTransferItem(window, dtItem);
338
+ items.push(createClipboardItem(window, blob));
346
339
  }
347
340
  const written = clipboard && await clipboard.write(items).then(() => true, () => false);
348
341
  if (!written) {
349
342
  throw new Error("The Clipboard API is unavailable.");
350
343
  }
351
344
  }
352
- if (typeof afterEach === "function") {
353
- afterEach(() => resetClipboardStubOnView(window));
345
+ if (typeof globalThis.afterEach === "function") {
346
+ globalThis.afterEach(() => resetClipboardStubOnView(globalThis.window));
354
347
  }
355
- if (typeof afterAll === "function") {
356
- afterAll(() => detachClipboardStubFromView(window));
348
+ if (typeof globalThis.afterAll === "function") {
349
+ globalThis.afterAll(() => detachClipboardStubFromView(globalThis.window));
357
350
  }
358
351
 
359
352
  // src/utils/edit/isContentEditable.ts
@@ -380,6 +373,7 @@ function getValue(element) {
380
373
  }
381
374
 
382
375
  // src/utils/edit/buildTimeValue.ts
376
+ var parseInt = globalThis.parseInt;
383
377
  function buildTimeValue(value) {
384
378
  const onlyDigitsValue = value.replace(/\D/g, "");
385
379
  if (onlyDigitsValue.length < 2) {
@@ -436,11 +430,11 @@ function getSpaceUntilMaxLength(element) {
436
430
  return maxLength ? maxLength - value.length : void 0;
437
431
  }
438
432
  function getSanitizedMaxLength(element) {
439
- var _a3;
433
+ var _a;
440
434
  if (!supportsMaxLength(element)) {
441
435
  return void 0;
442
436
  }
443
- const attr = (_a3 = element.getAttribute("maxlength")) != null ? _a3 : "";
437
+ const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
444
438
  return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
445
439
  }
446
440
  function supportsMaxLength(element) {
@@ -509,7 +503,7 @@ function editContenteditable(config, element, inputRange, data, inputType) {
509
503
  function editInputElement(config, element, inputRange, data, inputType) {
510
504
  let dataToInsert = data;
511
505
  const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
512
- if (spaceUntilMaxLength !== void 0) {
506
+ if (spaceUntilMaxLength !== void 0 && data.length > 0) {
513
507
  if (spaceUntilMaxLength > 0) {
514
508
  dataToInsert = data.substring(0, spaceUntilMaxLength);
515
509
  } else {
@@ -533,6 +527,7 @@ function editInputElement(config, element, inputRange, data, inputType) {
533
527
  if (isValidDateOrTimeValue(element, newValue)) {
534
528
  commitInput(config, element, newOffset, {});
535
529
  dispatchUIEvent(config, element, "change");
530
+ clearInitialValue(element);
536
531
  }
537
532
  } else {
538
533
  commitInput(config, element, newOffset, {
@@ -577,9 +572,9 @@ function commitInput(config, element, newOffset, inputInit) {
577
572
  }
578
573
  }
579
574
  function isValidNumberInput(value) {
580
- var _a3, _b;
575
+ var _a, _b;
581
576
  const valueParts = value.split("e", 2);
582
- return !(/[^\d.\-e]/.test(value) || Number((_a3 = value.match(/-/g)) == null ? void 0 : _a3.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
577
+ return !(/[^\d.\-e]/.test(value) || Number((_a = value.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
583
578
  }
584
579
 
585
580
  // src/utils/edit/isEditable.ts
@@ -608,8 +603,8 @@ function isEditableInput(element) {
608
603
  // src/utils/edit/setFiles.ts
609
604
  var fakeFiles = Symbol("files and value properties are mocked");
610
605
  function setFiles(el, files) {
611
- var _a3;
612
- (_a3 = el[fakeFiles]) == null ? void 0 : _a3.restore();
606
+ var _a;
607
+ (_a = el[fakeFiles]) == null ? void 0 : _a.restore();
613
608
  const objectDescriptors = Object.getOwnPropertyDescriptors(el);
614
609
  const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
615
610
  function restore() {
@@ -627,11 +622,11 @@ function setFiles(el, files) {
627
622
  value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
628
623
  get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
629
624
  set(v) {
630
- var _a4;
625
+ var _a2;
631
626
  if (v === "") {
632
627
  restore();
633
628
  } else {
634
- (_a4 = objectDescriptors.value.set) == null ? void 0 : _a4.call(el, v);
629
+ (_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
635
630
  }
636
631
  }
637
632
  }),
@@ -658,7 +653,7 @@ function eventWrapper(cb) {
658
653
 
659
654
  // src/utils/misc/isDisabled.ts
660
655
  function isDisabled(element) {
661
- var _a3;
656
+ var _a;
662
657
  for (let el = element; el; el = el.parentElement) {
663
658
  if (isElementType(el, [
664
659
  "button",
@@ -672,7 +667,7 @@ function isDisabled(element) {
672
667
  return true;
673
668
  }
674
669
  } else if (isElementType(el, "fieldset")) {
675
- if (el.hasAttribute("disabled") && !((_a3 = el.querySelector(":scope > legend")) == null ? void 0 : _a3.contains(element))) {
670
+ if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
676
671
  return true;
677
672
  }
678
673
  } else if (el.tagName.includes("-")) {
@@ -685,13 +680,13 @@ function isDisabled(element) {
685
680
  }
686
681
 
687
682
  // src/utils/focus/getActiveElement.ts
688
- function getActiveElement(document2) {
689
- const activeElement = document2.activeElement;
683
+ function getActiveElement(document) {
684
+ const activeElement = document.activeElement;
690
685
  if (activeElement == null ? void 0 : activeElement.shadowRoot) {
691
686
  return getActiveElement(activeElement.shadowRoot);
692
687
  } else {
693
688
  if (isDisabled(activeElement)) {
694
- return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
689
+ return document.ownerDocument ? document.ownerDocument.body : document.body;
695
690
  }
696
691
  return activeElement;
697
692
  }
@@ -805,7 +800,7 @@ function isTextNode(node) {
805
800
  return node.nodeType === 3;
806
801
  }
807
802
  function walkNodes(node, direction, callback) {
808
- var _a3;
803
+ var _a;
809
804
  for (; ; ) {
810
805
  const sibling = node[`${direction}Sibling`];
811
806
  if (sibling) {
@@ -813,7 +808,7 @@ function walkNodes(node, direction, callback) {
813
808
  if (callback(node)) {
814
809
  return node;
815
810
  }
816
- } else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a3 = node.ownerDocument) == null ? void 0 : _a3.body))) {
811
+ } else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
817
812
  node = node.parentNode;
818
813
  } else {
819
814
  break;
@@ -829,7 +824,7 @@ function getDescendant(node, direction) {
829
824
 
830
825
  // src/utils/focus/selection.ts
831
826
  function setSelectionRange(element, anchorOffset, focusOffset) {
832
- var _a3;
827
+ var _a;
833
828
  if (hasOwnSelection(element)) {
834
829
  return setSelection({
835
830
  focusNode: element,
@@ -837,7 +832,7 @@ function setSelectionRange(element, anchorOffset, focusOffset) {
837
832
  focusOffset
838
833
  });
839
834
  }
840
- if (isContentEditable(element) && ((_a3 = element.firstChild) == null ? void 0 : _a3.nodeType) === 3) {
835
+ if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
841
836
  return setSelection({
842
837
  focusNode: element.firstChild,
843
838
  anchorOffset,
@@ -871,7 +866,7 @@ function getElement2(node) {
871
866
  return node.nodeType === 1 ? node : node.parentElement;
872
867
  }
873
868
  function updateSelectionOnFocus(element) {
874
- var _a3;
869
+ var _a;
875
870
  const selection = element.ownerDocument.getSelection();
876
871
  if (!(selection == null ? void 0 : selection.focusNode)) {
877
872
  return;
@@ -880,7 +875,7 @@ function updateSelectionOnFocus(element) {
880
875
  const contenteditable = getContentEditable(selection.focusNode);
881
876
  if (contenteditable) {
882
877
  if (!selection.isCollapsed) {
883
- const focusNode = ((_a3 = contenteditable.firstChild) == null ? void 0 : _a3.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
878
+ const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
884
879
  selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
885
880
  }
886
881
  } else {
@@ -889,12 +884,12 @@ function updateSelectionOnFocus(element) {
889
884
  }
890
885
  }
891
886
  function getInputRange(focusNode) {
892
- var _a3;
887
+ var _a;
893
888
  const typeAndSelection = getTargetTypeAndSelection(focusNode);
894
889
  if (typeAndSelection.type === "input") {
895
890
  return typeAndSelection.selection;
896
891
  } else if (typeAndSelection.type === "contenteditable") {
897
- return (_a3 = typeAndSelection.selection) == null ? void 0 : _a3.getRangeAt(0);
892
+ return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
898
893
  }
899
894
  }
900
895
  function setSelection({
@@ -903,7 +898,7 @@ function setSelection({
903
898
  anchorNode = focusNode,
904
899
  anchorOffset = focusOffset
905
900
  }) {
906
- var _a3, _b;
901
+ var _a, _b;
907
902
  const typeAndSelection = getTargetTypeAndSelection(focusNode);
908
903
  if (typeAndSelection.type === "input") {
909
904
  return setUISelection(focusNode, {
@@ -911,7 +906,7 @@ function setSelection({
911
906
  focusOffset
912
907
  });
913
908
  }
914
- (_b = (_a3 = anchorNode.ownerDocument) == null ? void 0 : _a3.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
909
+ (_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
915
910
  }
916
911
  function moveSelection(node, direction) {
917
912
  if (hasOwnSelection(node)) {
@@ -922,7 +917,7 @@ function moveSelection(node, direction) {
922
917
  });
923
918
  } else {
924
919
  const selection = node.ownerDocument.getSelection();
925
- if (!selection) {
920
+ if (!(selection == null ? void 0 : selection.focusNode)) {
926
921
  return;
927
922
  }
928
923
  if (selection.isCollapsed) {
@@ -984,9 +979,9 @@ function focus(element) {
984
979
 
985
980
  // src/utils/misc/isVisible.ts
986
981
  function isVisible(element) {
987
- const window2 = getWindow(element);
982
+ const window = getWindow(element);
988
983
  for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
989
- const { display, visibility } = window2.getComputedStyle(el);
984
+ const { display, visibility } = window.getComputedStyle(el);
990
985
  if (display === "none") {
991
986
  return false;
992
987
  }
@@ -999,8 +994,8 @@ function isVisible(element) {
999
994
 
1000
995
  // src/utils/focus/getTabDestination.ts
1001
996
  function getTabDestination(activeElement, shift) {
1002
- const document2 = activeElement.ownerDocument;
1003
- const focusableElements = document2.querySelectorAll(FOCUSABLE_SELECTOR);
997
+ const document = activeElement.ownerDocument;
998
+ const focusableElements = document.querySelectorAll(FOCUSABLE_SELECTOR);
1004
999
  const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex") !== "-1" && !isDisabled(el) && isVisible(el));
1005
1000
  if (activeElement.getAttribute("tabindex") !== "-1") {
1006
1001
  enabledElements.sort((a, b) => {
@@ -1017,7 +1012,7 @@ function getTabDestination(activeElement, shift) {
1017
1012
  });
1018
1013
  }
1019
1014
  const checkedRadio = {};
1020
- let prunedElements = [document2.body];
1015
+ let prunedElements = [document.body];
1021
1016
  const activeRadioGroup = isElementType(activeElement, "input", {
1022
1017
  type: "radio"
1023
1018
  }) ? activeElement.name : void 0;
@@ -1050,7 +1045,7 @@ function getTabDestination(activeElement, shift) {
1050
1045
 
1051
1046
  // src/utils/focus/selectAll.ts
1052
1047
  function selectAll(target) {
1053
- var _a3;
1048
+ var _a;
1054
1049
  if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
1055
1050
  return setSelection({
1056
1051
  focusNode: target,
@@ -1058,7 +1053,7 @@ function selectAll(target) {
1058
1053
  focusOffset: getUIValue(target).length
1059
1054
  });
1060
1055
  }
1061
- const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
1056
+ const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
1062
1057
  setSelection({
1063
1058
  focusNode,
1064
1059
  anchorOffset: 0,
@@ -1066,11 +1061,11 @@ function selectAll(target) {
1066
1061
  });
1067
1062
  }
1068
1063
  function isAllSelected(target) {
1069
- var _a3;
1064
+ var _a;
1070
1065
  if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
1071
1066
  return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
1072
1067
  }
1073
- const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
1068
+ const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
1074
1069
  const selection = target.ownerDocument.getSelection();
1075
1070
  return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
1076
1071
  }
@@ -1130,12 +1125,12 @@ function readPrintableChar(text, pos, context) {
1130
1125
  };
1131
1126
  }
1132
1127
  function readTag(text, pos, startBracket, context) {
1133
- var _a3, _b, _c;
1128
+ var _a, _b, _c;
1134
1129
  const releasePreviousModifier = text[pos] === "/" ? "/" : "";
1135
1130
  pos += releasePreviousModifier.length;
1136
1131
  const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
1137
1132
  pos += Number(escapedDescriptor);
1138
- const descriptor = escapedDescriptor ? text[pos] : (_a3 = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a3[0];
1133
+ const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
1139
1134
  assertDescriptor(descriptor, text, pos, context);
1140
1135
  pos += descriptor.length;
1141
1136
  const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
@@ -1207,18 +1202,25 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
1207
1202
  // src/utils/misc/level.ts
1208
1203
  var Level = Symbol("Api level refs");
1209
1204
  function setLevelRef(config, level) {
1210
- var _a3;
1211
- (_a3 = config[Level]) != null ? _a3 : config[Level] = {};
1205
+ var _a;
1206
+ (_a = config[Level]) != null ? _a : config[Level] = {};
1212
1207
  config[Level][level] = {};
1213
1208
  }
1214
1209
  function getLevelRef(config, level) {
1215
- var _a3;
1216
- return (_a3 = config[Level]) == null ? void 0 : _a3[level];
1210
+ var _a;
1211
+ return (_a = config[Level]) == null ? void 0 : _a[level];
1217
1212
  }
1218
1213
 
1219
1214
  // src/utils/misc/wait.ts
1220
- function wait(time) {
1221
- return new Promise((resolve) => setTimeout(() => resolve(), time));
1215
+ function wait(config) {
1216
+ const delay = config.delay;
1217
+ if (typeof delay !== "number") {
1218
+ return;
1219
+ }
1220
+ return Promise.all([
1221
+ new Promise((resolve) => globalThis.setTimeout(() => resolve(), delay)),
1222
+ config.advanceTimers(delay)
1223
+ ]);
1222
1224
  }
1223
1225
 
1224
1226
  // src/keyboard/keyMap.ts
@@ -1299,14 +1301,15 @@ var defaultOptionsDirect = {
1299
1301
  applyAccept: true,
1300
1302
  autoModify: true,
1301
1303
  delay: 0,
1302
- document: global.document,
1304
+ document: globalThis.document,
1303
1305
  keyboardMap: defaultKeyMap,
1304
1306
  pointerMap: defaultKeyMap2,
1305
1307
  pointerEventsCheck: 2 /* EachApiCall */,
1306
1308
  skipAutoClose: false,
1307
1309
  skipClick: false,
1308
1310
  skipHover: false,
1309
- writeToClipboard: false
1311
+ writeToClipboard: false,
1312
+ advanceTimers: () => Promise.resolve()
1310
1313
  };
1311
1314
  var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
1312
1315
  writeToClipboard: true
@@ -1314,14 +1317,19 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
1314
1317
 
1315
1318
  // src/utils/pointer/cssPointerEvents.ts
1316
1319
  function hasPointerEvents(element) {
1317
- const window2 = getWindow(element);
1318
- for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1319
- const pointerEvents = window2.getComputedStyle(el).pointerEvents;
1320
+ var _a;
1321
+ return ((_a = closestPointerEventsDeclaration(element)) == null ? void 0 : _a.pointerEvents) !== "none";
1322
+ }
1323
+ function closestPointerEventsDeclaration(element) {
1324
+ const window = getWindow(element);
1325
+ for (let el = element, tree = []; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1326
+ tree.push(el);
1327
+ const pointerEvents = window.getComputedStyle(el).pointerEvents;
1320
1328
  if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
1321
- return pointerEvents !== "none";
1329
+ return { pointerEvents, tree };
1322
1330
  }
1323
1331
  }
1324
- return true;
1332
+ return void 0;
1325
1333
  }
1326
1334
  var PointerEventsCheck = Symbol("Last check for pointer-events");
1327
1335
  function assertPointerEvents(config, element) {
@@ -1330,15 +1338,59 @@ function assertPointerEvents(config, element) {
1330
1338
  if (!needsCheck) {
1331
1339
  return;
1332
1340
  }
1333
- const result = hasPointerEvents(element);
1341
+ const declaration = closestPointerEventsDeclaration(element);
1334
1342
  element[PointerEventsCheck] = {
1335
1343
  [1 /* Call */]: getLevelRef(config, 1 /* Call */),
1336
1344
  [2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
1337
- result
1345
+ result: (declaration == null ? void 0 : declaration.pointerEvents) !== "none"
1338
1346
  };
1339
- if (!result) {
1340
- throw new Error('Unable to perform pointer interaction as the element has or inherits pointer-events set to "none".');
1341
- }
1347
+ if ((declaration == null ? void 0 : declaration.pointerEvents) === "none") {
1348
+ throw new Error([
1349
+ `Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
1350
+ "",
1351
+ printTree(declaration.tree)
1352
+ ].join("\n"));
1353
+ }
1354
+ }
1355
+ function printTree(tree) {
1356
+ return tree.reverse().map((el, i) => [
1357
+ "".padEnd(i),
1358
+ el.tagName,
1359
+ el.id && `#${el.id}`,
1360
+ el.hasAttribute("data-testid") && `(testId=${el.getAttribute("data-testid")})`,
1361
+ getLabelDescr(el),
1362
+ tree.length > 1 && i === 0 && " <-- This element declared `pointer-events: none`",
1363
+ tree.length > 1 && i === tree.length - 1 && " <-- Asserted pointer events here"
1364
+ ].filter(Boolean).join("")).join("\n");
1365
+ }
1366
+ function getLabelDescr(element) {
1367
+ var _a, _b, _c, _d;
1368
+ let label;
1369
+ if (element.hasAttribute("aria-label")) {
1370
+ label = element.getAttribute("aria-label");
1371
+ } else if (element.hasAttribute("aria-labelledby")) {
1372
+ label = (_b = (_a = element.ownerDocument.getElementById(element.getAttribute("aria-labelledby"))) == null ? void 0 : _a.textContent) == null ? void 0 : _b.trim();
1373
+ } else if (isElementType(element, [
1374
+ "button",
1375
+ "input",
1376
+ "meter",
1377
+ "output",
1378
+ "progress",
1379
+ "select",
1380
+ "textarea"
1381
+ ]) && ((_c = element.labels) == null ? void 0 : _c.length)) {
1382
+ label = Array.from(element.labels).map((el) => {
1383
+ var _a2;
1384
+ return (_a2 = el.textContent) == null ? void 0 : _a2.trim();
1385
+ }).join("|");
1386
+ } else if (isElementType(element, "button")) {
1387
+ label = (_d = element.textContent) == null ? void 0 : _d.trim();
1388
+ }
1389
+ label = label == null ? void 0 : label.replace(/\n/g, " ");
1390
+ if (Number(label == null ? void 0 : label.length) > 30) {
1391
+ label = `${label == null ? void 0 : label.substring(0, 29)}\u2026`;
1392
+ }
1393
+ return label ? `(label=${label})` : "";
1342
1394
  }
1343
1395
  function hasBitFlag(conf, flag) {
1344
1396
  return (conf & flag) > 0;
@@ -1428,9 +1480,9 @@ function assignPositionInit(obj, {
1428
1480
  screenX,
1429
1481
  screenY
1430
1482
  }) {
1431
- var _a3, _b, _c, _d;
1483
+ var _a, _b, _c, _d;
1432
1484
  assignProps(obj, {
1433
- x: (_a3 = x != null ? x : clientX) != null ? _a3 : 0,
1485
+ x: (_a = x != null ? x : clientX) != null ? _a : 0,
1434
1486
  y: (_b = y != null ? y : clientY) != null ? _b : 0,
1435
1487
  clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
1436
1488
  clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
@@ -1484,8 +1536,8 @@ behavior.cut = (event, target, config) => {
1484
1536
 
1485
1537
  // src/event/behavior/keydown.ts
1486
1538
  behavior.keydown = (event, target, config) => {
1487
- var _a3, _b;
1488
- return (_b = (_a3 = keydownBehavior[event.key]) == null ? void 0 : _a3.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
1539
+ var _a, _b;
1540
+ return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
1489
1541
  };
1490
1542
  var keydownBehavior = {
1491
1543
  ArrowLeft: (event, target) => () => moveSelection(target, -1),
@@ -1507,8 +1559,8 @@ var keydownBehavior = {
1507
1559
  End: (event, target) => {
1508
1560
  if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
1509
1561
  return () => {
1510
- var _a3, _b;
1511
- const newPos = (_b = (_a3 = getValue(target)) == null ? void 0 : _a3.length) != null ? _b : 0;
1562
+ var _a, _b;
1563
+ const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
1512
1564
  setSelectionRange(target, newPos, newPos);
1513
1565
  };
1514
1566
  }
@@ -1600,8 +1652,8 @@ var SubmitSingleInputOnEnter = [
1600
1652
 
1601
1653
  // src/event/behavior/keyup.ts
1602
1654
  behavior.keyup = (event, target, config) => {
1603
- var _a3;
1604
- return (_a3 = keyupBehavior[event.key]) == null ? void 0 : _a3.call(keyupBehavior, event, target, config);
1655
+ var _a;
1656
+ return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
1605
1657
  };
1606
1658
  var keyupBehavior = {
1607
1659
  " ": (event, target, config) => {
@@ -1615,8 +1667,8 @@ var keyupBehavior = {
1615
1667
  behavior.paste = (event, target, config) => {
1616
1668
  if (isEditable(target)) {
1617
1669
  return () => {
1618
- var _a3;
1619
- const insertData = (_a3 = event.clipboardData) == null ? void 0 : _a3.getData("text");
1670
+ var _a;
1671
+ const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
1620
1672
  if (insertData) {
1621
1673
  input(config, target, insertData, "insertFromPaste");
1622
1674
  }
@@ -1632,10 +1684,10 @@ function wrapEvent(cb, _element) {
1632
1684
 
1633
1685
  // src/event/dispatchEvent.ts
1634
1686
  function dispatchEvent(config, target, event, preventDefault = false) {
1635
- var _a3, _b;
1687
+ var _a, _b;
1636
1688
  const type3 = event.type;
1637
1689
  const behaviorImplementation = preventDefault ? () => {
1638
- } : (_b = (_a3 = behavior)[type3]) == null ? void 0 : _b.call(_a3, event, target, config);
1690
+ } : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
1639
1691
  if (behaviorImplementation) {
1640
1692
  event.preventDefault();
1641
1693
  let defaultPrevented = false;
@@ -1678,13 +1730,18 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1678
1730
  return;
1679
1731
  }
1680
1732
  function intercept(...args) {
1681
- const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
1733
+ const {
1734
+ applyNative = true,
1735
+ realArgs,
1736
+ then
1737
+ } = interceptorImpl.call(this, ...args);
1682
1738
  const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
1683
1739
  if (target === "set") {
1684
1740
  realFunc.call(this, realArgs);
1685
1741
  } else {
1686
1742
  realFunc.call(this, ...realArgs);
1687
1743
  }
1744
+ then == null ? void 0 : then();
1688
1745
  }
1689
1746
  ;
1690
1747
  intercept[Interceptor] = Interceptor;
@@ -1746,9 +1803,9 @@ function setUISelection(element, {
1746
1803
  }
1747
1804
  }
1748
1805
  function getUISelection(element) {
1749
- var _a3, _b, _c;
1806
+ var _a, _b, _c;
1750
1807
  const sel = (_c = element[UISelection]) != null ? _c : {
1751
- anchorOffset: (_a3 = element.selectionStart) != null ? _a3 : 0,
1808
+ anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
1752
1809
  focusOffset: (_b = element.selectionEnd) != null ? _b : 0
1753
1810
  };
1754
1811
  return __spreadProps(__spreadValues({}, sel), {
@@ -1766,12 +1823,11 @@ function valueInterceptor(v) {
1766
1823
  if (isUI) {
1767
1824
  this[UIValue] = String(v);
1768
1825
  setPreviousValue(this, String(this.value));
1769
- } else {
1770
- trackOrSetValue(this, String(v));
1771
1826
  }
1772
1827
  return {
1773
1828
  applyNative: !!isUI,
1774
- realArgs: sanitizeValue(this, v)
1829
+ realArgs: sanitizeValue(this, v),
1830
+ then: isUI ? void 0 : () => trackOrSetValue(this, String(v))
1775
1831
  };
1776
1832
  }
1777
1833
  function sanitizeValue(element, v) {
@@ -1784,6 +1840,9 @@ function prepareValueInterceptor(element) {
1784
1840
  prepareInterceptor(element, "value", valueInterceptor);
1785
1841
  }
1786
1842
  function setUIValue(element, value) {
1843
+ if (element[InitialValue] === void 0) {
1844
+ element[InitialValue] = element.value;
1845
+ }
1787
1846
  element.value = {
1788
1847
  [UIValue]: UIValue,
1789
1848
  toString: () => value
@@ -1792,8 +1851,8 @@ function setUIValue(element, value) {
1792
1851
  function getUIValue(element) {
1793
1852
  return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
1794
1853
  }
1795
- function setInitialValue(element) {
1796
- element[InitialValue] = element.value;
1854
+ function clearInitialValue(element) {
1855
+ element[InitialValue] = void 0;
1797
1856
  }
1798
1857
  function getInitialValue(element) {
1799
1858
  return element[InitialValue];
@@ -1808,22 +1867,21 @@ function startTrackValue(element) {
1808
1867
  });
1809
1868
  }
1810
1869
  function trackOrSetValue(element, v) {
1811
- var _a3, _b, _c;
1812
- (_b = (_a3 = element[TrackChanges]) == null ? void 0 : _a3.tracked) == null ? void 0 : _b.push(v);
1870
+ var _a, _b, _c;
1871
+ (_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
1813
1872
  if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
1814
1873
  setCleanValue(element, v);
1815
1874
  }
1816
1875
  }
1817
1876
  function setCleanValue(element, v) {
1818
1877
  element[UIValue] = void 0;
1819
- element[InitialValue] = v;
1820
1878
  setUISelection(element, { focusOffset: v.length });
1821
1879
  }
1822
1880
  function endTrackValue(element) {
1823
- var _a3, _b;
1881
+ var _a, _b;
1824
1882
  const changes = element[TrackChanges];
1825
1883
  element[TrackChanges] = void 0;
1826
- const isJustReactStateUpdate = ((_a3 = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a3.length) === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === changes.nextValue;
1884
+ const isJustReactStateUpdate = ((_a = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a.length) === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === changes.nextValue;
1827
1885
  if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
1828
1886
  setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
1829
1887
  }
@@ -1832,36 +1890,36 @@ function endTrackValue(element) {
1832
1890
 
1833
1891
  // src/document/index.ts
1834
1892
  var isPrepared = Symbol("Node prepared with document state workarounds");
1835
- function prepareDocument(document2) {
1836
- if (document2[isPrepared]) {
1893
+ function prepareDocument(document) {
1894
+ if (document[isPrepared]) {
1837
1895
  return;
1838
1896
  }
1839
- document2.addEventListener("focus", (e) => {
1897
+ document.addEventListener("focus", (e) => {
1840
1898
  const el = e.target;
1841
1899
  prepareElement(el);
1842
1900
  }, {
1843
1901
  capture: true,
1844
1902
  passive: true
1845
1903
  });
1846
- if (document2.activeElement) {
1847
- prepareElement(document2.activeElement);
1904
+ if (document.activeElement) {
1905
+ prepareElement(document.activeElement);
1848
1906
  }
1849
- document2.addEventListener("blur", (e) => {
1907
+ document.addEventListener("blur", (e) => {
1850
1908
  const el = e.target;
1851
1909
  const initialValue = getInitialValue(el);
1852
- if (typeof initialValue === "string" && el.value !== initialValue) {
1853
- dispatchUIEvent({}, el, "change");
1910
+ if (initialValue !== void 0) {
1911
+ if (el.value !== initialValue) {
1912
+ dispatchUIEvent({}, el, "change");
1913
+ }
1914
+ clearInitialValue(el);
1854
1915
  }
1855
1916
  }, {
1856
1917
  capture: true,
1857
1918
  passive: true
1858
1919
  });
1859
- document2[isPrepared] = isPrepared;
1920
+ document[isPrepared] = isPrepared;
1860
1921
  }
1861
1922
  function prepareElement(el) {
1862
- if ("value" in el) {
1863
- setInitialValue(el);
1864
- }
1865
1923
  if (el[isPrepared]) {
1866
1924
  return;
1867
1925
  }
@@ -1896,11 +1954,11 @@ function isModifierLock(key) {
1896
1954
  return modifierLocks.includes(key);
1897
1955
  }
1898
1956
  function preKeydownBehavior(config, { key }, element) {
1899
- var _a3;
1957
+ var _a;
1900
1958
  if (isModifierKey(key)) {
1901
1959
  config.keyboardState.modifiers[key] = true;
1902
1960
  if (key === "AltGraph") {
1903
- const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
1961
+ const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1904
1962
  dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
1905
1963
  }
1906
1964
  } else if (isModifierLock(key)) {
@@ -1920,9 +1978,9 @@ function preKeyupBehavior(config, { key }) {
1920
1978
  }
1921
1979
  }
1922
1980
  function postKeyupBehavior(config, { key }, element) {
1923
- var _a3;
1981
+ var _a;
1924
1982
  if (key === "AltGraph") {
1925
- const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
1983
+ const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1926
1984
  dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
1927
1985
  }
1928
1986
  }
@@ -1931,14 +1989,14 @@ function postKeyupBehavior(config, { key }, element) {
1931
1989
  async function keyboardAction(config, actions) {
1932
1990
  for (let i = 0; i < actions.length; i++) {
1933
1991
  await keyboardKeyAction(config, actions[i]);
1934
- if (typeof config.delay === "number" && i < actions.length - 1) {
1935
- await wait(config.delay);
1992
+ if (i < actions.length - 1) {
1993
+ await wait(config);
1936
1994
  }
1937
1995
  }
1938
1996
  }
1939
1997
  async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf, repeat }) {
1940
- const { document: document2, keyboardState, delay } = config;
1941
- const getCurrentElement = () => getActive(document2);
1998
+ const { document, keyboardState } = config;
1999
+ const getCurrentElement = () => getActive(document);
1942
2000
  const pressed = keyboardState.pressed.find((p) => p.keyDef === keyDef);
1943
2001
  if (pressed) {
1944
2002
  await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
@@ -1950,8 +2008,8 @@ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf,
1950
2008
  if (unpreventedDefault && hasKeyPress(keyDef, config)) {
1951
2009
  await keypress(keyDef, getCurrentElement, config);
1952
2010
  }
1953
- if (typeof delay === "number" && i < repeat) {
1954
- await wait(delay);
2011
+ if (i < repeat) {
2012
+ await wait(config);
1955
2013
  }
1956
2014
  }
1957
2015
  if (releaseSelf) {
@@ -1959,9 +2017,9 @@ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf,
1959
2017
  }
1960
2018
  }
1961
2019
  }
1962
- function getActive(document2) {
1963
- var _a3;
1964
- return (_a3 = getActiveElement(document2)) != null ? _a3 : document2.body;
2020
+ function getActive(document) {
2021
+ var _a;
2022
+ return (_a = getActiveElement(document)) != null ? _a : document.body;
1965
2023
  }
1966
2024
  async function releaseAllKeys(config) {
1967
2025
  const getCurrentElement = () => getActive(config.document);
@@ -1995,13 +2053,13 @@ async function keyup(keyDef, getCurrentElement, config, unprevented) {
1995
2053
  postKeyupBehavior(config, keyDef, element);
1996
2054
  }
1997
2055
  function hasKeyPress(keyDef, config) {
1998
- var _a3;
1999
- return (((_a3 = keyDef.key) == null ? void 0 : _a3.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
2056
+ var _a;
2057
+ return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
2000
2058
  }
2001
2059
 
2002
2060
  // src/keyboard/parseKeyDef.ts
2003
2061
  function parseKeyDef(keyboardMap, text) {
2004
- var _a3;
2062
+ var _a;
2005
2063
  const defs = [];
2006
2064
  do {
2007
2065
  const {
@@ -2012,15 +2070,15 @@ function parseKeyDef(keyboardMap, text) {
2012
2070
  releaseSelf = true,
2013
2071
  repeat
2014
2072
  } = readNextDescriptor(text, "keyboard");
2015
- const keyDef = (_a3 = keyboardMap.find((def) => {
2016
- var _a4, _b;
2073
+ const keyDef = (_a = keyboardMap.find((def) => {
2074
+ var _a2, _b;
2017
2075
  if (type3 === "[") {
2018
- return ((_a4 = def.code) == null ? void 0 : _a4.toLowerCase()) === descriptor.toLowerCase();
2076
+ return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
2019
2077
  } else if (type3 === "{") {
2020
2078
  return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
2021
2079
  }
2022
2080
  return def.key === descriptor;
2023
- })) != null ? _a3 : {
2081
+ })) != null ? _a : {
2024
2082
  key: "Unknown",
2025
2083
  code: "Unknown",
2026
2084
  [type3 === "[" ? "code" : "key"]: descriptor
@@ -2097,8 +2155,8 @@ function firePointerEvent(config, target, type3, {
2097
2155
  }
2098
2156
  init.button = getMouseButton(button != null ? button : 0);
2099
2157
  init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
2100
- var _a3;
2101
- return (_a3 = p.keyDef.button) != null ? _a3 : 0;
2158
+ var _a;
2159
+ return (_a = p.keyDef.button) != null ? _a : 0;
2102
2160
  }));
2103
2161
  if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
2104
2162
  init.detail = clickCount;
@@ -2256,7 +2314,7 @@ function getNextPointerId(state) {
2256
2314
  return state.pointerId;
2257
2315
  }
2258
2316
  function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
2259
- var _a3, _b, _c;
2317
+ var _a, _b, _c;
2260
2318
  setLevelRef(config, 2 /* Trigger */);
2261
2319
  assertPointerEvents(config, target);
2262
2320
  const { pointerState } = config;
@@ -2279,7 +2337,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
2279
2337
  }
2280
2338
  }
2281
2339
  }
2282
- if (((_a3 = pointerState.activeClickCount) == null ? void 0 : _a3[0]) !== name) {
2340
+ if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
2283
2341
  delete pointerState.activeClickCount;
2284
2342
  }
2285
2343
  const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
@@ -2462,17 +2520,15 @@ function getTextRange(text, pos, clickCount) {
2462
2520
 
2463
2521
  // src/pointer/pointerAction.ts
2464
2522
  async function pointerAction(config, actions) {
2465
- var _a3, _b;
2523
+ var _a, _b;
2466
2524
  for (let i = 0; i < actions.length; i++) {
2467
2525
  const action = actions[i];
2468
2526
  const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
2469
- const target = (_a3 = action.target) != null ? _a3 : getPrevTarget(pointerName, config.pointerState);
2527
+ const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
2470
2528
  const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
2471
2529
  await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
2472
- if (typeof config.delay === "number") {
2473
- if (i < actions.length - 1) {
2474
- await wait(config.delay);
2475
- }
2530
+ if (i < actions.length - 1) {
2531
+ await wait(config);
2476
2532
  }
2477
2533
  }
2478
2534
  delete config.pointerState.activeClickCount;
@@ -2499,14 +2555,14 @@ async function pointer(input2) {
2499
2555
  });
2500
2556
  return pointerAction(this[Config], actions).then(() => void 0);
2501
2557
  }
2502
- function createPointerState(document2) {
2558
+ function createPointerState(document) {
2503
2559
  return {
2504
2560
  pointerId: 1,
2505
2561
  position: {
2506
2562
  mouse: {
2507
2563
  pointerType: "mouse",
2508
2564
  pointerId: 1,
2509
- target: document2.body,
2565
+ target: document.body,
2510
2566
  coords: {
2511
2567
  clientX: 0,
2512
2568
  clientY: 0,
@@ -2580,9 +2636,9 @@ async function tab({
2580
2636
 
2581
2637
  // src/clipboard/copy.ts
2582
2638
  async function copy() {
2583
- var _a3;
2639
+ var _a;
2584
2640
  const doc = this[Config].document;
2585
- const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2641
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2586
2642
  const clipboardData = copySelection(target);
2587
2643
  if (clipboardData.items.length === 0) {
2588
2644
  return;
@@ -2597,9 +2653,9 @@ async function copy() {
2597
2653
 
2598
2654
  // src/clipboard/cut.ts
2599
2655
  async function cut() {
2600
- var _a3;
2656
+ var _a;
2601
2657
  const doc = this[Config].document;
2602
- const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2658
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2603
2659
  const clipboardData = copySelection(target);
2604
2660
  if (clipboardData.items.length === 0) {
2605
2661
  return;
@@ -2614,9 +2670,9 @@ async function cut() {
2614
2670
 
2615
2671
  // src/clipboard/paste.ts
2616
2672
  async function paste(clipboardData) {
2617
- var _a3, _b;
2673
+ var _a, _b;
2618
2674
  const doc = this[Config].document;
2619
- const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2675
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2620
2676
  const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
2621
2677
  throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
2622
2678
  });
@@ -2706,6 +2762,7 @@ async function selectOptionsBase(newValue, select, values) {
2706
2762
  if (withPointerEvents) {
2707
2763
  this.dispatchUIEvent(option, "click");
2708
2764
  }
2765
+ await wait(this[Config]);
2709
2766
  }
2710
2767
  } else if (selectedOptions.length === 1) {
2711
2768
  const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
@@ -2724,6 +2781,7 @@ async function selectOptionsBase(newValue, select, values) {
2724
2781
  this.dispatchUIEvent(select, "mouseup");
2725
2782
  this.dispatchUIEvent(select, "click");
2726
2783
  }
2784
+ await wait(this[Config]);
2727
2785
  } else {
2728
2786
  throw (0, import_dom4.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
2729
2787
  }
@@ -2768,10 +2826,10 @@ async function upload(element, fileOrFiles) {
2768
2826
  return;
2769
2827
  const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
2770
2828
  const fileDialog = () => {
2771
- var _a3;
2772
- if (files.length === ((_a3 = input2.files) == null ? void 0 : _a3.length) && files.every((f, i) => {
2773
- var _a4;
2774
- return f === ((_a4 = input2.files) == null ? void 0 : _a4.item(i));
2829
+ var _a;
2830
+ if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
2831
+ var _a2;
2832
+ return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
2775
2833
  })) {
2776
2834
  return;
2777
2835
  }
@@ -2806,22 +2864,22 @@ function wrapAsync(implementation) {
2806
2864
 
2807
2865
  // src/setup/setup.ts
2808
2866
  function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
2809
- const document2 = getDocument(options, node);
2867
+ const document = getDocument(options, node, defaults);
2810
2868
  const {
2811
2869
  keyboardState = createKeyboardState(),
2812
- pointerState = createPointerState(document2)
2870
+ pointerState = createPointerState(document)
2813
2871
  } = options;
2814
2872
  return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
2815
- document: document2,
2873
+ document,
2816
2874
  keyboardState,
2817
2875
  pointerState
2818
2876
  });
2819
2877
  }
2820
2878
  function setupMain(options = {}) {
2821
- var _a3;
2879
+ var _a;
2822
2880
  const config = createConfig(options);
2823
2881
  prepareDocument(config.document);
2824
- const view = (_a3 = config.document.defaultView) != null ? _a3 : window;
2882
+ const view = (_a = config.document.defaultView) != null ? _a : globalThis.window;
2825
2883
  attachClipboardStubToView(view);
2826
2884
  return doSetup(config);
2827
2885
  }
@@ -2839,7 +2897,10 @@ function setupSub(options) {
2839
2897
  function wrapAndBindImpl(instance, impl) {
2840
2898
  function method(...args) {
2841
2899
  setLevelRef(instance[Config], 1 /* Call */);
2842
- return wrapAsync(() => impl.apply(instance, args));
2900
+ return wrapAsync(() => impl.apply(instance, args).then(async (ret) => {
2901
+ await wait(instance[Config]);
2902
+ return ret;
2903
+ }));
2843
2904
  }
2844
2905
  Object.defineProperty(method, "name", { get: () => impl.name });
2845
2906
  return method;
@@ -2856,9 +2917,9 @@ function doSetup(config) {
2856
2917
  setup: setupSub.bind(instance)
2857
2918
  });
2858
2919
  }
2859
- function getDocument(options, node) {
2860
- var _a3, _b;
2861
- return (_b = (_a3 = options.document) != null ? _a3 : node && getDocumentFromNode(node)) != null ? _b : document;
2920
+ function getDocument(options, node, defaults) {
2921
+ var _a, _b;
2922
+ return (_b = (_a = options.document) != null ? _a : node && getDocumentFromNode(node)) != null ? _b : defaults.document;
2862
2923
  }
2863
2924
 
2864
2925
  // src/setup/directApi.ts