@testing-library/user-event 14.0.1 → 14.0.2

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
@@ -72,7 +72,7 @@ function isClickableInput(element) {
72
72
  }
73
73
 
74
74
  // src/utils/dataTransfer/Blob.ts
75
- function readBlobText(blob) {
75
+ function readBlobText(blob, FileReader) {
76
76
  return new Promise((res, rej) => {
77
77
  const fr = new FileReader();
78
78
  fr.onerror = rej;
@@ -156,8 +156,8 @@ var DataTransferStub = class {
156
156
  this.files = createFileList([]);
157
157
  }
158
158
  getData(format) {
159
- var _a;
160
- const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
159
+ var _a3;
160
+ const match = (_a3 = this.items.find(getTypeMatcher(format, true))) != null ? _a3 : 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(files = []) {
199
- const dt = typeof DataTransfer === "undefined" ? new DataTransferStub() : new DataTransfer();
198
+ function createDataTransfer(window2, files = []) {
199
+ const dt = typeof window2.DataTransfer === "undefined" ? new DataTransferStub() : new window2.DataTransfer();
200
200
  Object.defineProperty(dt, "files", { get: () => createFileList(files) });
201
201
  return dt;
202
202
  }
203
- function getBlobFromDataTransferItem(item) {
203
+ function getBlobFromDataTransferItem(window2, item) {
204
204
  if (item.kind === "file") {
205
205
  return item.getAsFile();
206
206
  }
@@ -208,12 +208,21 @@ function getBlobFromDataTransferItem(item) {
208
208
  item.getAsString((s) => {
209
209
  data = s;
210
210
  });
211
- return new Blob([data], { type: item.type });
211
+ return new window2.Blob([data], { type: item.type });
212
+ }
213
+
214
+ // src/utils/misc/getWindow.ts
215
+ var import_helpers = require("@testing-library/dom/dist/helpers.js");
216
+ function getWindow(node) {
217
+ return (0, import_helpers.getWindowFromNode)(node);
212
218
  }
213
219
 
214
220
  // src/utils/dataTransfer/Clipboard.ts
221
+ var Window = Symbol("Window reference");
222
+ var _a;
215
223
  var ClipboardItemStub = class {
216
224
  constructor(data) {
225
+ this[_a] = window;
217
226
  this.data = data;
218
227
  }
219
228
  get types() {
@@ -224,14 +233,17 @@ var ClipboardItemStub = class {
224
233
  if (!data) {
225
234
  throw new Error(`${type3} is not one of the available MIME types on this item.`);
226
235
  }
227
- return data instanceof Blob ? data : new Blob([data], { type: type3 });
236
+ return data instanceof this[Window].Blob ? data : new this[Window].Blob([data], { type: type3 });
228
237
  }
229
238
  };
239
+ _a = Window;
230
240
  var ClipboardStubControl = Symbol("Manage ClipboardSub");
231
- var ClipboardStub = class extends EventTarget {
241
+ var _a2;
242
+ var ClipboardStub = class extends window.EventTarget {
232
243
  constructor() {
233
244
  super(...arguments);
234
245
  this.items = [];
246
+ this[_a2] = window;
235
247
  }
236
248
  async read() {
237
249
  return Array.from(this.items);
@@ -241,7 +253,7 @@ var ClipboardStub = class extends EventTarget {
241
253
  for (const item of this.items) {
242
254
  const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
243
255
  if (type3) {
244
- text += await item.getType(type3).then((b) => readBlobText(b));
256
+ text += await item.getType(type3).then((b) => readBlobText(b, this[Window].FileReader));
245
257
  }
246
258
  }
247
259
  return text;
@@ -250,16 +262,22 @@ var ClipboardStub = class extends EventTarget {
250
262
  this.items = data;
251
263
  }
252
264
  async writeText(text) {
253
- this.items = [createClipboardItem(text)];
265
+ this.items = [createClipboardItem(this[Window], text)];
254
266
  }
255
267
  };
256
- ClipboardStubControl;
257
- function createClipboardItem(...blobs) {
258
- const constructor = typeof ClipboardItem === "undefined" ? ClipboardItemStub : ClipboardItem;
259
- return new constructor(Object.fromEntries(blobs.map((b) => [
268
+ _a2 = Window, ClipboardStubControl;
269
+ function createClipboardItem(window2, ...blobs) {
270
+ const data = Object.fromEntries(blobs.map((b) => [
260
271
  typeof b === "string" ? "text/plain" : b.type,
261
272
  Promise.resolve(b)
262
- ])));
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
+ }
263
281
  }
264
282
  function attachClipboardStubToView(window2) {
265
283
  if (window2.navigator.clipboard instanceof ClipboardStub) {
@@ -267,9 +285,11 @@ function attachClipboardStubToView(window2) {
267
285
  }
268
286
  const realClipboard = Object.getOwnPropertyDescriptor(window2.navigator, "clipboard");
269
287
  let stub = new ClipboardStub();
288
+ stub[Window] = window2;
270
289
  const control = {
271
290
  resetClipboardStub: () => {
272
291
  stub = new ClipboardStub();
292
+ stub[Window] = window2;
273
293
  stub[ClipboardStubControl] = control;
274
294
  },
275
295
  detachClipboardStub: () => {
@@ -301,28 +321,28 @@ function detachClipboardStubFromView(window2) {
301
321
  }
302
322
  }
303
323
  async function readDataTransferFromClipboard(document2) {
304
- var _a;
305
- const clipboard = (_a = document2.defaultView) == null ? void 0 : _a.navigator.clipboard;
324
+ const window2 = document2.defaultView;
325
+ const clipboard = window2 == null ? void 0 : window2.navigator.clipboard;
306
326
  const items = clipboard && await clipboard.read();
307
327
  if (!items) {
308
328
  throw new Error("The Clipboard API is unavailable.");
309
329
  }
310
- const dt = createDataTransfer();
330
+ const dt = createDataTransfer(window2);
311
331
  for (const item of items) {
312
332
  for (const type3 of item.types) {
313
- dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b)));
333
+ dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b, window2.FileReader)));
314
334
  }
315
335
  }
316
336
  return dt;
317
337
  }
318
338
  async function writeDataTransferToClipboard(document2, clipboardData) {
319
- var _a;
320
- const clipboard = (_a = document2.defaultView) == null ? void 0 : _a.navigator.clipboard;
339
+ const window2 = getWindow(document2);
340
+ const clipboard = window2.navigator.clipboard;
321
341
  const items = [];
322
342
  for (let i = 0; i < clipboardData.items.length; i++) {
323
343
  const dtItem = clipboardData.items[i];
324
- const blob = getBlobFromDataTransferItem(dtItem);
325
- items.push(createClipboardItem(blob));
344
+ const blob = getBlobFromDataTransferItem(window2, dtItem);
345
+ items.push(createClipboardItem(window2, blob));
326
346
  }
327
347
  const written = clipboard && await clipboard.write(items).then(() => true, () => false);
328
348
  if (!written) {
@@ -416,11 +436,11 @@ function getSpaceUntilMaxLength(element) {
416
436
  return maxLength ? maxLength - value.length : void 0;
417
437
  }
418
438
  function getSanitizedMaxLength(element) {
419
- var _a;
439
+ var _a3;
420
440
  if (!supportsMaxLength(element)) {
421
441
  return void 0;
422
442
  }
423
- const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
443
+ const attr = (_a3 = element.getAttribute("maxlength")) != null ? _a3 : "";
424
444
  return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
425
445
  }
426
446
  function supportsMaxLength(element) {
@@ -557,9 +577,9 @@ function commitInput(config, element, newOffset, inputInit) {
557
577
  }
558
578
  }
559
579
  function isValidNumberInput(value) {
560
- var _a, _b;
580
+ var _a3, _b;
561
581
  const valueParts = value.split("e", 2);
562
- 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]));
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]));
563
583
  }
564
584
 
565
585
  // src/utils/edit/isEditable.ts
@@ -588,8 +608,8 @@ function isEditableInput(element) {
588
608
  // src/utils/edit/setFiles.ts
589
609
  var fakeFiles = Symbol("files and value properties are mocked");
590
610
  function setFiles(el, files) {
591
- var _a;
592
- (_a = el[fakeFiles]) == null ? void 0 : _a.restore();
611
+ var _a3;
612
+ (_a3 = el[fakeFiles]) == null ? void 0 : _a3.restore();
593
613
  const objectDescriptors = Object.getOwnPropertyDescriptors(el);
594
614
  const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
595
615
  function restore() {
@@ -607,11 +627,11 @@ function setFiles(el, files) {
607
627
  value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
608
628
  get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
609
629
  set(v) {
610
- var _a2;
630
+ var _a4;
611
631
  if (v === "") {
612
632
  restore();
613
633
  } else {
614
- (_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
634
+ (_a4 = objectDescriptors.value.set) == null ? void 0 : _a4.call(el, v);
615
635
  }
616
636
  }
617
637
  }),
@@ -638,7 +658,7 @@ function eventWrapper(cb) {
638
658
 
639
659
  // src/utils/misc/isDisabled.ts
640
660
  function isDisabled(element) {
641
- var _a;
661
+ var _a3;
642
662
  for (let el = element; el; el = el.parentElement) {
643
663
  if (isElementType(el, [
644
664
  "button",
@@ -652,7 +672,7 @@ function isDisabled(element) {
652
672
  return true;
653
673
  }
654
674
  } else if (isElementType(el, "fieldset")) {
655
- if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
675
+ if (el.hasAttribute("disabled") && !((_a3 = el.querySelector(":scope > legend")) == null ? void 0 : _a3.contains(element))) {
656
676
  return true;
657
677
  }
658
678
  } else if (el.tagName.includes("-")) {
@@ -785,7 +805,7 @@ function isTextNode(node) {
785
805
  return node.nodeType === 3;
786
806
  }
787
807
  function walkNodes(node, direction, callback) {
788
- var _a;
808
+ var _a3;
789
809
  for (; ; ) {
790
810
  const sibling = node[`${direction}Sibling`];
791
811
  if (sibling) {
@@ -793,7 +813,7 @@ function walkNodes(node, direction, callback) {
793
813
  if (callback(node)) {
794
814
  return node;
795
815
  }
796
- } else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
816
+ } else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a3 = node.ownerDocument) == null ? void 0 : _a3.body))) {
797
817
  node = node.parentNode;
798
818
  } else {
799
819
  break;
@@ -809,7 +829,7 @@ function getDescendant(node, direction) {
809
829
 
810
830
  // src/utils/focus/selection.ts
811
831
  function setSelectionRange(element, anchorOffset, focusOffset) {
812
- var _a;
832
+ var _a3;
813
833
  if (hasOwnSelection(element)) {
814
834
  return setSelection({
815
835
  focusNode: element,
@@ -817,7 +837,7 @@ function setSelectionRange(element, anchorOffset, focusOffset) {
817
837
  focusOffset
818
838
  });
819
839
  }
820
- if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
840
+ if (isContentEditable(element) && ((_a3 = element.firstChild) == null ? void 0 : _a3.nodeType) === 3) {
821
841
  return setSelection({
822
842
  focusNode: element.firstChild,
823
843
  anchorOffset,
@@ -851,7 +871,7 @@ function getElement2(node) {
851
871
  return node.nodeType === 1 ? node : node.parentElement;
852
872
  }
853
873
  function updateSelectionOnFocus(element) {
854
- var _a;
874
+ var _a3;
855
875
  const selection = element.ownerDocument.getSelection();
856
876
  if (!(selection == null ? void 0 : selection.focusNode)) {
857
877
  return;
@@ -860,7 +880,7 @@ function updateSelectionOnFocus(element) {
860
880
  const contenteditable = getContentEditable(selection.focusNode);
861
881
  if (contenteditable) {
862
882
  if (!selection.isCollapsed) {
863
- const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
883
+ const focusNode = ((_a3 = contenteditable.firstChild) == null ? void 0 : _a3.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
864
884
  selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
865
885
  }
866
886
  } else {
@@ -869,12 +889,12 @@ function updateSelectionOnFocus(element) {
869
889
  }
870
890
  }
871
891
  function getInputRange(focusNode) {
872
- var _a;
892
+ var _a3;
873
893
  const typeAndSelection = getTargetTypeAndSelection(focusNode);
874
894
  if (typeAndSelection.type === "input") {
875
895
  return typeAndSelection.selection;
876
896
  } else if (typeAndSelection.type === "contenteditable") {
877
- return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
897
+ return (_a3 = typeAndSelection.selection) == null ? void 0 : _a3.getRangeAt(0);
878
898
  }
879
899
  }
880
900
  function setSelection({
@@ -883,7 +903,7 @@ function setSelection({
883
903
  anchorNode = focusNode,
884
904
  anchorOffset = focusOffset
885
905
  }) {
886
- var _a, _b;
906
+ var _a3, _b;
887
907
  const typeAndSelection = getTargetTypeAndSelection(focusNode);
888
908
  if (typeAndSelection.type === "input") {
889
909
  return setUISelection(focusNode, {
@@ -891,7 +911,7 @@ function setSelection({
891
911
  focusOffset
892
912
  });
893
913
  }
894
- (_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
914
+ (_b = (_a3 = anchorNode.ownerDocument) == null ? void 0 : _a3.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
895
915
  }
896
916
  function moveSelection(node, direction) {
897
917
  if (hasOwnSelection(node)) {
@@ -922,7 +942,7 @@ function moveSelection(node, direction) {
922
942
  // src/utils/focus/copySelection.ts
923
943
  function copySelection(target) {
924
944
  const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
925
- const dt = createDataTransfer();
945
+ const dt = createDataTransfer(getWindow(target));
926
946
  for (const type3 in data) {
927
947
  if (data[type3]) {
928
948
  dt.setData(type3, data[type3]);
@@ -963,9 +983,8 @@ function focus(element) {
963
983
  }
964
984
 
965
985
  // src/utils/misc/isVisible.ts
966
- var import_helpers = require("@testing-library/dom/dist/helpers.js");
967
986
  function isVisible(element) {
968
- const window2 = (0, import_helpers.getWindowFromNode)(element);
987
+ const window2 = getWindow(element);
969
988
  for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
970
989
  const { display, visibility } = window2.getComputedStyle(el);
971
990
  if (display === "none") {
@@ -1031,7 +1050,7 @@ function getTabDestination(activeElement, shift) {
1031
1050
 
1032
1051
  // src/utils/focus/selectAll.ts
1033
1052
  function selectAll(target) {
1034
- var _a;
1053
+ var _a3;
1035
1054
  if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
1036
1055
  return setSelection({
1037
1056
  focusNode: target,
@@ -1039,7 +1058,7 @@ function selectAll(target) {
1039
1058
  focusOffset: getUIValue(target).length
1040
1059
  });
1041
1060
  }
1042
- const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
1061
+ const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
1043
1062
  setSelection({
1044
1063
  focusNode,
1045
1064
  anchorOffset: 0,
@@ -1047,11 +1066,11 @@ function selectAll(target) {
1047
1066
  });
1048
1067
  }
1049
1068
  function isAllSelected(target) {
1050
- var _a;
1069
+ var _a3;
1051
1070
  if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
1052
1071
  return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
1053
1072
  }
1054
- const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
1073
+ const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
1055
1074
  const selection = target.ownerDocument.getSelection();
1056
1075
  return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
1057
1076
  }
@@ -1111,12 +1130,12 @@ function readPrintableChar(text, pos, context) {
1111
1130
  };
1112
1131
  }
1113
1132
  function readTag(text, pos, startBracket, context) {
1114
- var _a, _b, _c;
1133
+ var _a3, _b, _c;
1115
1134
  const releasePreviousModifier = text[pos] === "/" ? "/" : "";
1116
1135
  pos += releasePreviousModifier.length;
1117
1136
  const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
1118
1137
  pos += Number(escapedDescriptor);
1119
- const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
1138
+ const descriptor = escapedDescriptor ? text[pos] : (_a3 = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a3[0];
1120
1139
  assertDescriptor(descriptor, text, pos, context);
1121
1140
  pos += descriptor.length;
1122
1141
  const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
@@ -1188,13 +1207,13 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
1188
1207
  // src/utils/misc/level.ts
1189
1208
  var Level = Symbol("Api level refs");
1190
1209
  function setLevelRef(config, level) {
1191
- var _a;
1192
- (_a = config[Level]) != null ? _a : config[Level] = {};
1210
+ var _a3;
1211
+ (_a3 = config[Level]) != null ? _a3 : config[Level] = {};
1193
1212
  config[Level][level] = {};
1194
1213
  }
1195
1214
  function getLevelRef(config, level) {
1196
- var _a;
1197
- return (_a = config[Level]) == null ? void 0 : _a[level];
1215
+ var _a3;
1216
+ return (_a3 = config[Level]) == null ? void 0 : _a3[level];
1198
1217
  }
1199
1218
 
1200
1219
  // src/utils/misc/wait.ts
@@ -1202,9 +1221,6 @@ function wait(time) {
1202
1221
  return new Promise((resolve) => setTimeout(() => resolve(), time));
1203
1222
  }
1204
1223
 
1205
- // src/utils/pointer/cssPointerEvents.ts
1206
- var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
1207
-
1208
1224
  // src/keyboard/keyMap.ts
1209
1225
  var defaultKeyMap = [
1210
1226
  ..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
@@ -1298,7 +1314,7 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
1298
1314
 
1299
1315
  // src/utils/pointer/cssPointerEvents.ts
1300
1316
  function hasPointerEvents(element) {
1301
- const window2 = (0, import_helpers2.getWindowFromNode)(element);
1317
+ const window2 = getWindow(element);
1302
1318
  for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1303
1319
  const pointerEvents = window2.getComputedStyle(el).pointerEvents;
1304
1320
  if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
@@ -1412,9 +1428,9 @@ function assignPositionInit(obj, {
1412
1428
  screenX,
1413
1429
  screenY
1414
1430
  }) {
1415
- var _a, _b, _c, _d;
1431
+ var _a3, _b, _c, _d;
1416
1432
  assignProps(obj, {
1417
- x: (_a = x != null ? x : clientX) != null ? _a : 0,
1433
+ x: (_a3 = x != null ? x : clientX) != null ? _a3 : 0,
1418
1434
  y: (_b = y != null ? y : clientY) != null ? _b : 0,
1419
1435
  clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
1420
1436
  clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
@@ -1451,7 +1467,7 @@ behavior.click = (event, target, config) => {
1451
1467
  } else if (isElementType(target, "input", { type: "file" })) {
1452
1468
  return () => {
1453
1469
  blur(target);
1454
- target.dispatchEvent(new Event("fileDialog"));
1470
+ target.dispatchEvent(new (getWindow(target)).Event("fileDialog"));
1455
1471
  focus(target);
1456
1472
  };
1457
1473
  }
@@ -1468,8 +1484,8 @@ behavior.cut = (event, target, config) => {
1468
1484
 
1469
1485
  // src/event/behavior/keydown.ts
1470
1486
  behavior.keydown = (event, target, config) => {
1471
- var _a, _b;
1472
- return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(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);
1473
1489
  };
1474
1490
  var keydownBehavior = {
1475
1491
  ArrowLeft: (event, target) => () => moveSelection(target, -1),
@@ -1491,8 +1507,8 @@ var keydownBehavior = {
1491
1507
  End: (event, target) => {
1492
1508
  if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
1493
1509
  return () => {
1494
- var _a, _b;
1495
- const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
1510
+ var _a3, _b;
1511
+ const newPos = (_b = (_a3 = getValue(target)) == null ? void 0 : _a3.length) != null ? _b : 0;
1496
1512
  setSelectionRange(target, newPos, newPos);
1497
1513
  };
1498
1514
  }
@@ -1584,8 +1600,8 @@ var SubmitSingleInputOnEnter = [
1584
1600
 
1585
1601
  // src/event/behavior/keyup.ts
1586
1602
  behavior.keyup = (event, target, config) => {
1587
- var _a;
1588
- return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
1603
+ var _a3;
1604
+ return (_a3 = keyupBehavior[event.key]) == null ? void 0 : _a3.call(keyupBehavior, event, target, config);
1589
1605
  };
1590
1606
  var keyupBehavior = {
1591
1607
  " ": (event, target, config) => {
@@ -1599,8 +1615,8 @@ var keyupBehavior = {
1599
1615
  behavior.paste = (event, target, config) => {
1600
1616
  if (isEditable(target)) {
1601
1617
  return () => {
1602
- var _a;
1603
- const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
1618
+ var _a3;
1619
+ const insertData = (_a3 = event.clipboardData) == null ? void 0 : _a3.getData("text");
1604
1620
  if (insertData) {
1605
1621
  input(config, target, insertData, "insertFromPaste");
1606
1622
  }
@@ -1616,10 +1632,10 @@ function wrapEvent(cb, _element) {
1616
1632
 
1617
1633
  // src/event/dispatchEvent.ts
1618
1634
  function dispatchEvent(config, target, event, preventDefault = false) {
1619
- var _a, _b;
1635
+ var _a3, _b;
1620
1636
  const type3 = event.type;
1621
1637
  const behaviorImplementation = preventDefault ? () => {
1622
- } : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
1638
+ } : (_b = (_a3 = behavior)[type3]) == null ? void 0 : _b.call(_a3, event, target, config);
1623
1639
  if (behaviorImplementation) {
1624
1640
  event.preventDefault();
1625
1641
  let defaultPrevented = false;
@@ -1723,9 +1739,9 @@ function setUISelection(element, {
1723
1739
  }
1724
1740
  }
1725
1741
  function getUISelection(element) {
1726
- var _a, _b, _c;
1742
+ var _a3, _b, _c;
1727
1743
  const sel = (_c = element[UISelection]) != null ? _c : {
1728
- anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
1744
+ anchorOffset: (_a3 = element.selectionStart) != null ? _a3 : 0,
1729
1745
  focusOffset: (_b = element.selectionEnd) != null ? _b : 0
1730
1746
  };
1731
1747
  return __spreadProps(__spreadValues({}, sel), {
@@ -1785,8 +1801,8 @@ function startTrackValue(element) {
1785
1801
  });
1786
1802
  }
1787
1803
  function trackOrSetValue(element, v) {
1788
- var _a, _b, _c;
1789
- (_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
1804
+ var _a3, _b, _c;
1805
+ (_b = (_a3 = element[TrackChanges]) == null ? void 0 : _a3.tracked) == null ? void 0 : _b.push(v);
1790
1806
  if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
1791
1807
  setCleanValue(element, v);
1792
1808
  }
@@ -1797,10 +1813,10 @@ function setCleanValue(element, v) {
1797
1813
  setUISelection(element, { focusOffset: v.length });
1798
1814
  }
1799
1815
  function endTrackValue(element) {
1800
- var _a, _b;
1816
+ var _a3, _b;
1801
1817
  const changes = element[TrackChanges];
1802
1818
  element[TrackChanges] = void 0;
1803
- 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;
1819
+ 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;
1804
1820
  if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
1805
1821
  setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
1806
1822
  }
@@ -1873,11 +1889,11 @@ function isModifierLock(key) {
1873
1889
  return modifierLocks.includes(key);
1874
1890
  }
1875
1891
  function preKeydownBehavior(config, { key }, element) {
1876
- var _a;
1892
+ var _a3;
1877
1893
  if (isModifierKey(key)) {
1878
1894
  config.keyboardState.modifiers[key] = true;
1879
1895
  if (key === "AltGraph") {
1880
- const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1896
+ const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
1881
1897
  dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
1882
1898
  }
1883
1899
  } else if (isModifierLock(key)) {
@@ -1897,9 +1913,9 @@ function preKeyupBehavior(config, { key }) {
1897
1913
  }
1898
1914
  }
1899
1915
  function postKeyupBehavior(config, { key }, element) {
1900
- var _a;
1916
+ var _a3;
1901
1917
  if (key === "AltGraph") {
1902
- const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1918
+ const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
1903
1919
  dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
1904
1920
  }
1905
1921
  }
@@ -1937,8 +1953,8 @@ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf,
1937
1953
  }
1938
1954
  }
1939
1955
  function getActive(document2) {
1940
- var _a;
1941
- return (_a = getActiveElement(document2)) != null ? _a : document2.body;
1956
+ var _a3;
1957
+ return (_a3 = getActiveElement(document2)) != null ? _a3 : document2.body;
1942
1958
  }
1943
1959
  async function releaseAllKeys(config) {
1944
1960
  const getCurrentElement = () => getActive(config.document);
@@ -1972,13 +1988,13 @@ async function keyup(keyDef, getCurrentElement, config, unprevented) {
1972
1988
  postKeyupBehavior(config, keyDef, element);
1973
1989
  }
1974
1990
  function hasKeyPress(keyDef, config) {
1975
- var _a;
1976
- return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
1991
+ var _a3;
1992
+ return (((_a3 = keyDef.key) == null ? void 0 : _a3.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
1977
1993
  }
1978
1994
 
1979
1995
  // src/keyboard/parseKeyDef.ts
1980
1996
  function parseKeyDef(keyboardMap, text) {
1981
- var _a;
1997
+ var _a3;
1982
1998
  const defs = [];
1983
1999
  do {
1984
2000
  const {
@@ -1989,15 +2005,15 @@ function parseKeyDef(keyboardMap, text) {
1989
2005
  releaseSelf = true,
1990
2006
  repeat
1991
2007
  } = readNextDescriptor(text, "keyboard");
1992
- const keyDef = (_a = keyboardMap.find((def) => {
1993
- var _a2, _b;
2008
+ const keyDef = (_a3 = keyboardMap.find((def) => {
2009
+ var _a4, _b;
1994
2010
  if (type3 === "[") {
1995
- return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
2011
+ return ((_a4 = def.code) == null ? void 0 : _a4.toLowerCase()) === descriptor.toLowerCase();
1996
2012
  } else if (type3 === "{") {
1997
2013
  return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
1998
2014
  }
1999
2015
  return def.key === descriptor;
2000
- })) != null ? _a : {
2016
+ })) != null ? _a3 : {
2001
2017
  key: "Unknown",
2002
2018
  code: "Unknown",
2003
2019
  [type3 === "[" ? "code" : "key"]: descriptor
@@ -2074,8 +2090,8 @@ function firePointerEvent(config, target, type3, {
2074
2090
  }
2075
2091
  init.button = getMouseButton(button != null ? button : 0);
2076
2092
  init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
2077
- var _a;
2078
- return (_a = p.keyDef.button) != null ? _a : 0;
2093
+ var _a3;
2094
+ return (_a3 = p.keyDef.button) != null ? _a3 : 0;
2079
2095
  }));
2080
2096
  if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
2081
2097
  init.detail = clickCount;
@@ -2233,7 +2249,7 @@ function getNextPointerId(state) {
2233
2249
  return state.pointerId;
2234
2250
  }
2235
2251
  function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
2236
- var _a, _b, _c;
2252
+ var _a3, _b, _c;
2237
2253
  setLevelRef(config, 2 /* Trigger */);
2238
2254
  assertPointerEvents(config, target);
2239
2255
  const { pointerState } = config;
@@ -2256,7 +2272,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
2256
2272
  }
2257
2273
  }
2258
2274
  }
2259
- if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
2275
+ if (((_a3 = pointerState.activeClickCount) == null ? void 0 : _a3[0]) !== name) {
2260
2276
  delete pointerState.activeClickCount;
2261
2277
  }
2262
2278
  const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
@@ -2410,7 +2426,7 @@ function mousedownDefaultBehavior({
2410
2426
  node,
2411
2427
  offset: end
2412
2428
  });
2413
- const range = new Range();
2429
+ const range = target.ownerDocument.createRange();
2414
2430
  range.setStart(startNode, startOffset);
2415
2431
  range.setEnd(endNode, endOffset);
2416
2432
  position.selectionRange = range;
@@ -2439,11 +2455,11 @@ function getTextRange(text, pos, clickCount) {
2439
2455
 
2440
2456
  // src/pointer/pointerAction.ts
2441
2457
  async function pointerAction(config, actions) {
2442
- var _a, _b;
2458
+ var _a3, _b;
2443
2459
  for (let i = 0; i < actions.length; i++) {
2444
2460
  const action = actions[i];
2445
2461
  const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
2446
- const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
2462
+ const target = (_a3 = action.target) != null ? _a3 : getPrevTarget(pointerName, config.pointerState);
2447
2463
  const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
2448
2464
  await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
2449
2465
  if (typeof config.delay === "number") {
@@ -2557,9 +2573,9 @@ async function tab({
2557
2573
 
2558
2574
  // src/clipboard/copy.ts
2559
2575
  async function copy() {
2560
- var _a;
2576
+ var _a3;
2561
2577
  const doc = this[Config].document;
2562
- const target = (_a = doc.activeElement) != null ? _a : doc.body;
2578
+ const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2563
2579
  const clipboardData = copySelection(target);
2564
2580
  if (clipboardData.items.length === 0) {
2565
2581
  return;
@@ -2574,9 +2590,9 @@ async function copy() {
2574
2590
 
2575
2591
  // src/clipboard/cut.ts
2576
2592
  async function cut() {
2577
- var _a;
2593
+ var _a3;
2578
2594
  const doc = this[Config].document;
2579
- const target = (_a = doc.activeElement) != null ? _a : doc.body;
2595
+ const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2580
2596
  const clipboardData = copySelection(target);
2581
2597
  if (clipboardData.items.length === 0) {
2582
2598
  return;
@@ -2591,18 +2607,18 @@ async function cut() {
2591
2607
 
2592
2608
  // src/clipboard/paste.ts
2593
2609
  async function paste(clipboardData) {
2594
- var _a, _b;
2610
+ var _a3, _b;
2595
2611
  const doc = this[Config].document;
2596
- const target = (_a = doc.activeElement) != null ? _a : doc.body;
2597
- const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
2612
+ const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
2613
+ const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
2598
2614
  throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
2599
2615
  });
2600
2616
  this.dispatchUIEvent(target, "paste", {
2601
2617
  clipboardData: dataTransfer
2602
2618
  });
2603
2619
  }
2604
- function getClipboardDataFromString(text) {
2605
- const dt = createDataTransfer();
2620
+ function getClipboardDataFromString(doc, text) {
2621
+ const dt = createDataTransfer(getWindow(doc));
2606
2622
  dt.setData("text", text);
2607
2623
  return dt;
2608
2624
  }
@@ -2745,10 +2761,10 @@ async function upload(element, fileOrFiles) {
2745
2761
  return;
2746
2762
  const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
2747
2763
  const fileDialog = () => {
2748
- var _a;
2749
- if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
2750
- var _a2;
2751
- return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
2764
+ var _a3;
2765
+ if (files.length === ((_a3 = input2.files) == null ? void 0 : _a3.length) && files.every((f, i) => {
2766
+ var _a4;
2767
+ return f === ((_a4 = input2.files) == null ? void 0 : _a4.item(i));
2752
2768
  })) {
2753
2769
  return;
2754
2770
  }
@@ -2795,10 +2811,10 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
2795
2811
  });
2796
2812
  }
2797
2813
  function setupMain(options = {}) {
2798
- var _a;
2814
+ var _a3;
2799
2815
  const config = createConfig(options);
2800
2816
  prepareDocument(config.document);
2801
- const view = (_a = config.document.defaultView) != null ? _a : window;
2817
+ const view = (_a3 = config.document.defaultView) != null ? _a3 : window;
2802
2818
  attachClipboardStubToView(view);
2803
2819
  return doSetup(config);
2804
2820
  }
@@ -2834,8 +2850,8 @@ function doSetup(config) {
2834
2850
  });
2835
2851
  }
2836
2852
  function getDocument(options, node) {
2837
- var _a, _b;
2838
- return (_b = (_a = options.document) != null ? _a : node && getDocumentFromNode(node)) != null ? _b : document;
2853
+ var _a3, _b;
2854
+ return (_b = (_a3 = options.document) != null ? _a3 : node && getDocumentFromNode(node)) != null ? _b : document;
2839
2855
  }
2840
2856
 
2841
2857
  // src/setup/directApi.ts