@testing-library/user-event 14.0.0-alpha.7 → 14.0.0-beta.10

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 (198) hide show
  1. package/README.md +5 -192
  2. package/dist/index.cjs +3003 -0
  3. package/dist/index.mjs +3074 -0
  4. package/dist/types/clipboard/copy.d.ts +2 -0
  5. package/dist/types/clipboard/cut.d.ts +2 -0
  6. package/dist/types/clipboard/index.d.ts +3 -0
  7. package/dist/types/clipboard/paste.d.ts +2 -0
  8. package/dist/types/convenience/click.d.ts +4 -0
  9. package/dist/types/convenience/hover.d.ts +3 -0
  10. package/dist/types/convenience/index.d.ts +3 -0
  11. package/dist/types/convenience/tab.d.ts +4 -0
  12. package/dist/{document → types/document}/index.d.ts +0 -0
  13. package/dist/{document → types/document}/interceptor.d.ts +0 -0
  14. package/dist/{document → types/document}/selection.d.ts +0 -0
  15. package/dist/{document → types/document}/value.d.ts +0 -0
  16. package/dist/types/event/behavior/click.d.ts +1 -0
  17. package/dist/types/event/behavior/index.d.ts +3 -0
  18. package/dist/types/event/behavior/registry.d.ts +9 -0
  19. package/dist/types/event/createEvent.d.ts +8 -0
  20. package/dist/types/event/dispatchEvent.d.ts +2 -0
  21. package/dist/types/event/eventTypes.d.ts +2 -0
  22. package/dist/types/event/index.d.ts +6 -0
  23. package/dist/types/event/types.d.ts +13 -0
  24. package/dist/types/event/wrapEvent.d.ts +1 -0
  25. package/dist/types/index.d.ts +4 -0
  26. package/dist/types/keyboard/index.d.ts +7 -0
  27. package/dist/{keyboard → types/keyboard}/keyMap.d.ts +0 -0
  28. package/dist/types/keyboard/keyboardAction.d.ts +10 -0
  29. package/dist/{keyboard/getNextKeyDef.d.ts → types/keyboard/parseKeyDef.d.ts} +4 -6
  30. package/dist/{keyboard → types/keyboard}/plugins/arrow.d.ts +0 -0
  31. package/dist/{keyboard → types/keyboard}/plugins/character.d.ts +0 -0
  32. package/dist/types/keyboard/plugins/combination.d.ts +5 -0
  33. package/dist/{keyboard → types/keyboard}/plugins/control.d.ts +0 -0
  34. package/dist/{keyboard → types/keyboard}/plugins/functional.d.ts +0 -3
  35. package/dist/{keyboard → types/keyboard}/plugins/index.d.ts +0 -1
  36. package/dist/types/keyboard/plugins/modifiers.d.ts +8 -0
  37. package/dist/types/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +4 -0
  38. package/dist/{keyboard → types/keyboard}/shared/index.d.ts +0 -0
  39. package/dist/{keyboard → types/keyboard}/types.d.ts +22 -24
  40. package/dist/types/options.d.ts +117 -0
  41. package/dist/types/pointer/firePointerEvents.d.ts +11 -0
  42. package/dist/types/pointer/index.d.ts +10 -0
  43. package/dist/{pointer → types/pointer}/keyMap.d.ts +0 -0
  44. package/dist/types/pointer/parseKeyDef.d.ts +6 -0
  45. package/dist/{pointer → types/pointer}/pointerAction.d.ts +3 -2
  46. package/dist/types/pointer/pointerMove.d.ts +6 -0
  47. package/dist/types/pointer/pointerPress.d.ts +8 -0
  48. package/dist/{pointer → types/pointer}/resolveSelectionTarget.d.ts +0 -0
  49. package/dist/{pointer → types/pointer}/types.d.ts +2 -12
  50. package/dist/types/setup/api.d.ts +5 -0
  51. package/dist/types/setup/config.d.ts +10 -0
  52. package/dist/types/setup/directApi.d.ts +19 -0
  53. package/dist/types/setup/index.d.ts +36 -0
  54. package/dist/types/setup/setup.d.ts +20 -0
  55. package/dist/types/setup/wrapAsync.d.ts +4 -0
  56. package/dist/types/utility/clear.d.ts +2 -0
  57. package/dist/types/utility/index.d.ts +4 -0
  58. package/dist/types/utility/selectOptions.d.ts +3 -0
  59. package/dist/types/utility/type.d.ts +9 -0
  60. package/dist/types/utility/upload.d.ts +5 -0
  61. package/dist/{utils → types/utils}/click/isClickableInput.d.ts +0 -0
  62. package/dist/types/utils/dataTransfer/Blob.d.ts +1 -0
  63. package/dist/types/utils/dataTransfer/Clipboard.d.ts +9 -0
  64. package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -0
  65. package/dist/types/utils/dataTransfer/FileList.d.ts +1 -0
  66. package/dist/{utils → types/utils}/edit/buildTimeValue.d.ts +0 -0
  67. package/dist/{utils → types/utils}/edit/calculateNewValue.d.ts +1 -3
  68. package/dist/types/utils/edit/editInputElement.d.ts +14 -0
  69. package/dist/{utils → types/utils}/edit/getValue.d.ts +0 -0
  70. package/dist/{utils → types/utils}/edit/isContentEditable.d.ts +0 -0
  71. package/dist/{utils → types/utils}/edit/isEditable.d.ts +0 -0
  72. package/dist/{utils → types/utils}/edit/isValidDateValue.d.ts +0 -0
  73. package/dist/{utils → types/utils}/edit/isValidInputTimeValue.d.ts +0 -0
  74. package/dist/{utils → types/utils}/edit/maxLength.d.ts +0 -0
  75. package/dist/types/utils/edit/prepareInput.d.ts +8 -0
  76. package/dist/types/utils/edit/setFiles.d.ts +12 -0
  77. package/dist/{utils → types/utils}/focus/blur.d.ts +0 -0
  78. package/dist/types/utils/focus/copySelection.d.ts +1 -0
  79. package/dist/types/utils/focus/cursor.d.ts +9 -0
  80. package/dist/{utils → types/utils}/focus/focus.d.ts +3 -0
  81. package/dist/{utils → types/utils}/focus/getActiveElement.d.ts +0 -0
  82. package/dist/{utils → types/utils}/focus/getTabDestination.d.ts +0 -0
  83. package/dist/{utils → types/utils}/focus/isFocusable.d.ts +0 -0
  84. package/dist/types/utils/focus/selectAll.d.ts +5 -0
  85. package/dist/{utils → types/utils}/focus/selection.d.ts +0 -0
  86. package/dist/{utils → types/utils}/focus/selector.d.ts +0 -0
  87. package/dist/{utils → types/utils}/index.d.ts +15 -4
  88. package/dist/{utils → types/utils}/keyDef/readNextDescriptor.d.ts +0 -0
  89. package/dist/types/utils/keyboard/getKeyEventProps.d.ts +5 -0
  90. package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +15 -0
  91. package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
  92. package/dist/{utils → types/utils}/misc/eventWrapper.d.ts +0 -0
  93. package/dist/types/utils/misc/findClosest.d.ts +1 -0
  94. package/dist/types/utils/misc/getDocumentFromNode.d.ts +1 -0
  95. package/dist/{utils → types/utils}/misc/hasFormSubmit.d.ts +0 -0
  96. package/dist/{utils → types/utils}/misc/isDescendantOrSelf.d.ts +0 -0
  97. package/dist/{utils → types/utils}/misc/isDisabled.d.ts +0 -0
  98. package/dist/{utils → types/utils}/misc/isElementType.d.ts +0 -0
  99. package/dist/{utils → types/utils}/misc/isVisible.d.ts +0 -0
  100. package/dist/types/utils/misc/level.d.ts +17 -0
  101. package/dist/{utils → types/utils}/misc/wait.d.ts +0 -0
  102. package/dist/types/utils/pointer/cssPointerEvents.d.ts +15 -0
  103. package/dist/{utils → types/utils}/pointer/mouseButtons.d.ts +0 -0
  104. package/package.json +13 -30
  105. package/CHANGELOG.md +0 -5
  106. package/dist/clear.d.ts +0 -2
  107. package/dist/clear.js +0 -46
  108. package/dist/click.d.ts +0 -9
  109. package/dist/click.js +0 -62
  110. package/dist/document/index.js +0 -100
  111. package/dist/document/interceptor.js +0 -37
  112. package/dist/document/selection.js +0 -90
  113. package/dist/document/value.js +0 -77
  114. package/dist/hover.d.ts +0 -4
  115. package/dist/hover.js +0 -43
  116. package/dist/index.d.ts +0 -8
  117. package/dist/index.js +0 -22
  118. package/dist/keyboard/getEventProps.d.ts +0 -17
  119. package/dist/keyboard/getEventProps.js +0 -33
  120. package/dist/keyboard/getNextKeyDef.js +0 -85
  121. package/dist/keyboard/index.d.ts +0 -19
  122. package/dist/keyboard/index.js +0 -78
  123. package/dist/keyboard/keyMap.js +0 -143
  124. package/dist/keyboard/keyboardImplementation.d.ts +0 -3
  125. package/dist/keyboard/keyboardImplementation.js +0 -169
  126. package/dist/keyboard/plugins/arrow.js +0 -28
  127. package/dist/keyboard/plugins/character.js +0 -166
  128. package/dist/keyboard/plugins/control.js +0 -52
  129. package/dist/keyboard/plugins/functional.js +0 -140
  130. package/dist/keyboard/plugins/index.js +0 -40
  131. package/dist/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -3
  132. package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
  133. package/dist/keyboard/shared/index.js +0 -18
  134. package/dist/keyboard/specialCharMap.d.ts +0 -22
  135. package/dist/keyboard/specialCharMap.js +0 -30
  136. package/dist/keyboard/types.js +0 -19
  137. package/dist/paste.d.ts +0 -7
  138. package/dist/paste.js +0 -60
  139. package/dist/pointer/index.d.ts +0 -18
  140. package/dist/pointer/index.js +0 -90
  141. package/dist/pointer/keyMap.js +0 -29
  142. package/dist/pointer/parseKeyDef.d.ts +0 -6
  143. package/dist/pointer/parseKeyDef.js +0 -36
  144. package/dist/pointer/pointerAction.js +0 -52
  145. package/dist/pointer/pointerMove.d.ts +0 -5
  146. package/dist/pointer/pointerMove.js +0 -136
  147. package/dist/pointer/pointerPress.d.ts +0 -7
  148. package/dist/pointer/pointerPress.js +0 -330
  149. package/dist/pointer/resolveSelectionTarget.js +0 -75
  150. package/dist/pointer/types.js +0 -1
  151. package/dist/selectOptions.d.ts +0 -4
  152. package/dist/selectOptions.js +0 -142
  153. package/dist/setup.d.ts +0 -92
  154. package/dist/setup.js +0 -203
  155. package/dist/tab.d.ts +0 -5
  156. package/dist/tab.js +0 -12
  157. package/dist/type.d.ts +0 -14
  158. package/dist/type.js +0 -74
  159. package/dist/upload.d.ts +0 -10
  160. package/dist/upload.js +0 -92
  161. package/dist/utils/click/isClickableInput.js +0 -14
  162. package/dist/utils/edit/buildTimeValue.js +0 -44
  163. package/dist/utils/edit/calculateNewValue.js +0 -50
  164. package/dist/utils/edit/fireInputEvent.d.ts +0 -11
  165. package/dist/utils/edit/fireInputEvent.js +0 -65
  166. package/dist/utils/edit/getValue.js +0 -23
  167. package/dist/utils/edit/isContentEditable.js +0 -25
  168. package/dist/utils/edit/isEditable.js +0 -42
  169. package/dist/utils/edit/isValidDateValue.js +0 -12
  170. package/dist/utils/edit/isValidInputTimeValue.js +0 -12
  171. package/dist/utils/edit/maxLength.js +0 -50
  172. package/dist/utils/edit/prepareInput.d.ts +0 -4
  173. package/dist/utils/edit/prepareInput.js +0 -60
  174. package/dist/utils/focus/blur.js +0 -19
  175. package/dist/utils/focus/focus.js +0 -22
  176. package/dist/utils/focus/getActiveElement.js +0 -26
  177. package/dist/utils/focus/getTabDestination.js +0 -71
  178. package/dist/utils/focus/isFocusable.js +0 -12
  179. package/dist/utils/focus/selection.js +0 -190
  180. package/dist/utils/focus/selector.js +0 -8
  181. package/dist/utils/index.js +0 -408
  182. package/dist/utils/keyDef/readNextDescriptor.js +0 -102
  183. package/dist/utils/misc/eventWrapper.js +0 -16
  184. package/dist/utils/misc/findClosest.d.ts +0 -1
  185. package/dist/utils/misc/findClosest.js +0 -20
  186. package/dist/utils/misc/hasFormSubmit.js +0 -10
  187. package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
  188. package/dist/utils/misc/hasPointerEvents.js +0 -24
  189. package/dist/utils/misc/isDescendantOrSelf.js +0 -20
  190. package/dist/utils/misc/isDisabled.js +0 -12
  191. package/dist/utils/misc/isElementType.js +0 -24
  192. package/dist/utils/misc/isVisible.js +0 -24
  193. package/dist/utils/misc/wait.js +0 -10
  194. package/dist/utils/pointer/fakeEvent.d.ts +0 -20
  195. package/dist/utils/pointer/fakeEvent.js +0 -91
  196. package/dist/utils/pointer/firePointerEvents.d.ts +0 -14
  197. package/dist/utils/pointer/firePointerEvents.js +0 -55
  198. package/dist/utils/pointer/mouseButtons.js +0 -45
package/dist/index.cjs ADDED
@@ -0,0 +1,3003 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+ var __reExport = (target, module2, copyDefault, desc) => {
28
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
29
+ for (let key of __getOwnPropNames(module2))
30
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
31
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
32
+ }
33
+ return target;
34
+ };
35
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
36
+ return (module2, temp) => {
37
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
38
+ };
39
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
40
+
41
+ // src/index.ts
42
+ var src_exports = {};
43
+ __export(src_exports, {
44
+ PointerEventsCheckLevel: () => PointerEventsCheckLevel,
45
+ default: () => userEvent
46
+ });
47
+
48
+ // src/utils/misc/isElementType.ts
49
+ function isElementType(element, tag, props) {
50
+ if (element.namespaceURI && element.namespaceURI !== "http://www.w3.org/1999/xhtml") {
51
+ return false;
52
+ }
53
+ tag = Array.isArray(tag) ? tag : [tag];
54
+ if (!tag.includes(element.tagName.toLowerCase())) {
55
+ return false;
56
+ }
57
+ if (props) {
58
+ return Object.entries(props).every(([k, v]) => element[k] === v);
59
+ }
60
+ return true;
61
+ }
62
+
63
+ // src/utils/click/isClickableInput.ts
64
+ var CLICKABLE_INPUT_TYPES = [
65
+ "button",
66
+ "color",
67
+ "file",
68
+ "image",
69
+ "reset",
70
+ "submit",
71
+ "checkbox",
72
+ "radio"
73
+ ];
74
+ function isClickableInput(element) {
75
+ return isElementType(element, "button") || isElementType(element, "input") && CLICKABLE_INPUT_TYPES.includes(element.type);
76
+ }
77
+
78
+ // src/utils/dataTransfer/Blob.ts
79
+ function readBlobText(blob) {
80
+ return new Promise((res, rej) => {
81
+ const fr = new FileReader();
82
+ fr.onerror = rej;
83
+ fr.onabort = rej;
84
+ fr.onload = () => {
85
+ res(String(fr.result));
86
+ };
87
+ fr.readAsText(blob);
88
+ });
89
+ }
90
+
91
+ // src/utils/dataTransfer/FileList.ts
92
+ function createFileList(files) {
93
+ const list = __spreadProps(__spreadValues({}, files), {
94
+ length: files.length,
95
+ item: (index) => list[index],
96
+ [Symbol.iterator]: function* nextFile() {
97
+ for (let i = 0; i < list.length; i++) {
98
+ yield list[i];
99
+ }
100
+ }
101
+ });
102
+ list.constructor = FileList;
103
+ Object.setPrototypeOf(list, FileList.prototype);
104
+ Object.freeze(list);
105
+ return list;
106
+ }
107
+
108
+ // src/utils/dataTransfer/DataTransfer.ts
109
+ var DataTransferItemStub = class {
110
+ constructor(dataOrFile, type3) {
111
+ this.file = null;
112
+ this.data = void 0;
113
+ if (typeof dataOrFile === "string") {
114
+ this.kind = "string";
115
+ this.type = String(type3);
116
+ this.data = dataOrFile;
117
+ } else {
118
+ this.kind = "file";
119
+ this.type = dataOrFile.type;
120
+ this.file = dataOrFile;
121
+ }
122
+ }
123
+ getAsFile() {
124
+ return this.file;
125
+ }
126
+ getAsString(callback) {
127
+ if (typeof this.data === "string") {
128
+ callback(this.data);
129
+ }
130
+ }
131
+ webkitGetAsEntry() {
132
+ throw new Error("not implemented");
133
+ }
134
+ };
135
+ var DataTransferItemListStub = class extends Array {
136
+ add(...args) {
137
+ const item = new DataTransferItemStub(args[0], args[1]);
138
+ this.push(item);
139
+ return item;
140
+ }
141
+ clear() {
142
+ this.splice(0, this.length);
143
+ }
144
+ remove(index) {
145
+ this.splice(index, 1);
146
+ }
147
+ };
148
+ function getTypeMatcher(type3, exact) {
149
+ const [group, sub] = type3.split("/");
150
+ const isGroup = !sub || sub === "*";
151
+ return (item) => {
152
+ return exact ? item.type === (isGroup ? group : type3) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
153
+ };
154
+ }
155
+ var DataTransferStub = class {
156
+ constructor() {
157
+ this.dropEffect = "none";
158
+ this.effectAllowed = "uninitialized";
159
+ this.items = new DataTransferItemListStub();
160
+ this.files = createFileList([]);
161
+ }
162
+ getData(format) {
163
+ var _a;
164
+ const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
165
+ let text = "";
166
+ match == null ? void 0 : match.getAsString((t) => {
167
+ text = t;
168
+ });
169
+ return text;
170
+ }
171
+ setData(format, data) {
172
+ const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
173
+ const item = new DataTransferItemStub(data, format);
174
+ if (matchIndex >= 0) {
175
+ this.items.splice(matchIndex, 1, item);
176
+ } else {
177
+ this.items.push(item);
178
+ }
179
+ }
180
+ clearData(format) {
181
+ if (format) {
182
+ const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
183
+ if (matchIndex >= 0) {
184
+ this.items.remove(matchIndex);
185
+ }
186
+ } else {
187
+ this.items.clear();
188
+ }
189
+ }
190
+ get types() {
191
+ const t = [];
192
+ if (this.files.length) {
193
+ t.push("Files");
194
+ }
195
+ this.items.forEach((i) => t.push(i.type));
196
+ Object.freeze(t);
197
+ return t;
198
+ }
199
+ setDragImage() {
200
+ }
201
+ };
202
+ function createDataTransfer(files = []) {
203
+ const dt = typeof DataTransfer === "undefined" ? new DataTransferStub() : new DataTransfer();
204
+ Object.defineProperty(dt, "files", { get: () => createFileList(files) });
205
+ return dt;
206
+ }
207
+ function getBlobFromDataTransferItem(item) {
208
+ if (item.kind === "file") {
209
+ return item.getAsFile();
210
+ }
211
+ let data = "";
212
+ item.getAsString((s) => {
213
+ data = s;
214
+ });
215
+ return new Blob([data], { type: item.type });
216
+ }
217
+
218
+ // src/utils/dataTransfer/Clipboard.ts
219
+ var ClipboardItemStub = class {
220
+ constructor(data) {
221
+ this.data = data;
222
+ }
223
+ get types() {
224
+ return Array.from(Object.keys(this.data));
225
+ }
226
+ async getType(type3) {
227
+ const data = await this.data[type3];
228
+ if (!data) {
229
+ throw new Error(`${type3} is not one of the available MIME types on this item.`);
230
+ }
231
+ return data instanceof Blob ? data : new Blob([data], { type: type3 });
232
+ }
233
+ };
234
+ var ClipboardStubControl = Symbol("Manage ClipboardSub");
235
+ var ClipboardStub = class extends EventTarget {
236
+ constructor() {
237
+ super(...arguments);
238
+ this.items = [];
239
+ }
240
+ async read() {
241
+ return Array.from(this.items);
242
+ }
243
+ async readText() {
244
+ let text = "";
245
+ for (const item of this.items) {
246
+ const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
247
+ if (type3) {
248
+ text += await item.getType(type3).then((b) => readBlobText(b));
249
+ }
250
+ }
251
+ return text;
252
+ }
253
+ async write(data) {
254
+ this.items = data;
255
+ }
256
+ async writeText(text) {
257
+ this.items = [createClipboardItem(text)];
258
+ }
259
+ };
260
+ ClipboardStubControl;
261
+ function createClipboardItem(...blobs) {
262
+ const constructor = typeof ClipboardItem === "undefined" ? ClipboardItemStub : ClipboardItem;
263
+ return new constructor(Object.fromEntries(blobs.map((b) => [
264
+ typeof b === "string" ? "text/plain" : b.type,
265
+ Promise.resolve(b)
266
+ ])));
267
+ }
268
+ function attachClipboardStubToView(window2) {
269
+ if (window2.navigator.clipboard instanceof ClipboardStub) {
270
+ return window2.navigator.clipboard[ClipboardStubControl];
271
+ }
272
+ const realClipboard = Object.getOwnPropertyDescriptor(window2.navigator, "clipboard");
273
+ let stub = new ClipboardStub();
274
+ const control = {
275
+ resetClipboardStub: () => {
276
+ stub = new ClipboardStub();
277
+ stub[ClipboardStubControl] = control;
278
+ },
279
+ detachClipboardStub: () => {
280
+ if (realClipboard) {
281
+ Object.defineProperty(window2.navigator, "clipboard", realClipboard);
282
+ } else {
283
+ Object.defineProperty(window2.navigator, "clipboard", {
284
+ value: void 0,
285
+ configurable: true
286
+ });
287
+ }
288
+ }
289
+ };
290
+ stub[ClipboardStubControl] = control;
291
+ Object.defineProperty(window2.navigator, "clipboard", {
292
+ get: () => stub,
293
+ configurable: true
294
+ });
295
+ return stub[ClipboardStubControl];
296
+ }
297
+ function resetClipboardStubOnView(window2) {
298
+ if (window2.navigator.clipboard instanceof ClipboardStub) {
299
+ window2.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
300
+ }
301
+ }
302
+ function detachClipboardStubFromView(window2) {
303
+ if (window2.navigator.clipboard instanceof ClipboardStub) {
304
+ window2.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
305
+ }
306
+ }
307
+ async function readDataTransferFromClipboard(document2) {
308
+ var _a;
309
+ const clipboard = (_a = document2.defaultView) == null ? void 0 : _a.navigator.clipboard;
310
+ const items = clipboard && await clipboard.read();
311
+ if (!items) {
312
+ throw new Error("The Clipboard API is unavailable.");
313
+ }
314
+ const dt = createDataTransfer();
315
+ for (const item of items) {
316
+ for (const type3 of item.types) {
317
+ dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b)));
318
+ }
319
+ }
320
+ return dt;
321
+ }
322
+ async function writeDataTransferToClipboard(document2, clipboardData) {
323
+ var _a;
324
+ const clipboard = (_a = document2.defaultView) == null ? void 0 : _a.navigator.clipboard;
325
+ const items = [];
326
+ for (let i = 0; i < clipboardData.items.length; i++) {
327
+ const dtItem = clipboardData.items[i];
328
+ const blob = getBlobFromDataTransferItem(dtItem);
329
+ items.push(createClipboardItem(blob));
330
+ }
331
+ const written = clipboard && await clipboard.write(items).then(() => true, () => false);
332
+ if (!written) {
333
+ throw new Error("The Clipboard API is unavailable.");
334
+ }
335
+ }
336
+ if (typeof afterEach === "function") {
337
+ afterEach(() => resetClipboardStubOnView(window));
338
+ }
339
+ if (typeof afterAll === "function") {
340
+ afterAll(() => detachClipboardStubFromView(window));
341
+ }
342
+
343
+ // src/utils/edit/buildTimeValue.ts
344
+ function buildTimeValue(value) {
345
+ const onlyDigitsValue = value.replace(/\D/g, "");
346
+ if (onlyDigitsValue.length < 2) {
347
+ return value;
348
+ }
349
+ const firstDigit = parseInt(onlyDigitsValue[0], 10);
350
+ const secondDigit = parseInt(onlyDigitsValue[1], 10);
351
+ if (firstDigit >= 3 || firstDigit === 2 && secondDigit >= 4) {
352
+ let index;
353
+ if (firstDigit >= 3) {
354
+ index = 1;
355
+ } else {
356
+ index = 2;
357
+ }
358
+ return build(onlyDigitsValue, index);
359
+ }
360
+ if (value.length === 2) {
361
+ return value;
362
+ }
363
+ return build(onlyDigitsValue, 2);
364
+ }
365
+ function build(onlyDigitsValue, index) {
366
+ const hours = onlyDigitsValue.slice(0, index);
367
+ const validHours = Math.min(parseInt(hours, 10), 23);
368
+ const minuteCharacters = onlyDigitsValue.slice(index);
369
+ const parsedMinutes = parseInt(minuteCharacters, 10);
370
+ const validMinutes = Math.min(parsedMinutes, 59);
371
+ return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
372
+ }
373
+
374
+ // src/utils/edit/isValidDateValue.ts
375
+ function isValidDateValue(element, value) {
376
+ const clone = element.cloneNode();
377
+ clone.value = value;
378
+ return clone.value === value;
379
+ }
380
+
381
+ // src/utils/edit/isValidInputTimeValue.ts
382
+ function isValidInputTimeValue(element, timeValue) {
383
+ const clone = element.cloneNode();
384
+ clone.value = timeValue;
385
+ return clone.value === timeValue;
386
+ }
387
+
388
+ // src/utils/edit/calculateNewValue.ts
389
+ function calculateNewValue(inputData, node, {
390
+ startOffset,
391
+ endOffset
392
+ }, inputType) {
393
+ const value = getUIValue(node);
394
+ const prologEnd = Math.max(0, startOffset === endOffset && inputType === "deleteContentBackward" ? startOffset - 1 : startOffset);
395
+ const prolog = value.substring(0, prologEnd);
396
+ const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
397
+ const epilog = value.substring(epilogStart, value.length);
398
+ let newValue = `${prolog}${inputData}${epilog}`;
399
+ const newOffset = prologEnd + inputData.length;
400
+ if (node.type === "date" && !isValidDateValue(node, newValue)) {
401
+ newValue = value;
402
+ }
403
+ if (node.type === "time" && !isValidInputTimeValue(node, newValue)) {
404
+ if (isValidInputTimeValue(node, inputData)) {
405
+ newValue = inputData;
406
+ } else {
407
+ newValue = value;
408
+ }
409
+ }
410
+ return {
411
+ oldValue: value,
412
+ newValue,
413
+ newOffset
414
+ };
415
+ }
416
+
417
+ // src/utils/edit/isContentEditable.ts
418
+ function isContentEditable(element) {
419
+ return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
420
+ }
421
+ function getContentEditable(node) {
422
+ const element = getElement(node);
423
+ return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
424
+ }
425
+ function getElement(node) {
426
+ return node.nodeType === 1 ? node : node.parentElement;
427
+ }
428
+
429
+ // src/utils/edit/isEditable.ts
430
+ function isEditable(element) {
431
+ return isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element);
432
+ }
433
+ var editableInputTypes = /* @__PURE__ */ ((editableInputTypes2) => {
434
+ editableInputTypes2["text"] = "text";
435
+ editableInputTypes2["date"] = "date";
436
+ editableInputTypes2["datetime-local"] = "datetime-local";
437
+ editableInputTypes2["email"] = "email";
438
+ editableInputTypes2["month"] = "month";
439
+ editableInputTypes2["number"] = "number";
440
+ editableInputTypes2["password"] = "password";
441
+ editableInputTypes2["search"] = "search";
442
+ editableInputTypes2["tel"] = "tel";
443
+ editableInputTypes2["time"] = "time";
444
+ editableInputTypes2["url"] = "url";
445
+ editableInputTypes2["week"] = "week";
446
+ return editableInputTypes2;
447
+ })(editableInputTypes || {});
448
+ function isEditableInput(element) {
449
+ return isElementType(element, "input", { readOnly: false }) && Boolean(editableInputTypes[element.type]);
450
+ }
451
+
452
+ // src/utils/focus/selection.ts
453
+ function setSelectionRange(element, anchorOffset, focusOffset) {
454
+ var _a;
455
+ if (hasOwnSelection(element)) {
456
+ return setSelection({
457
+ focusNode: element,
458
+ anchorOffset,
459
+ focusOffset
460
+ });
461
+ }
462
+ if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
463
+ return setSelection({
464
+ focusNode: element.firstChild,
465
+ anchorOffset,
466
+ focusOffset
467
+ });
468
+ }
469
+ throw new Error("Not implemented. The result of this interaction is unreliable.");
470
+ }
471
+ function hasOwnSelection(node) {
472
+ return isElement(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
473
+ }
474
+ function isElement(node) {
475
+ return node.nodeType === 1;
476
+ }
477
+ function getTargetTypeAndSelection(node) {
478
+ const element = getElement2(node);
479
+ if (element && hasOwnSelection(element)) {
480
+ return {
481
+ type: "input",
482
+ selection: getUISelection(element)
483
+ };
484
+ }
485
+ const selection = element == null ? void 0 : element.ownerDocument.getSelection();
486
+ const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
487
+ return {
488
+ type: isCE ? "contenteditable" : "default",
489
+ selection
490
+ };
491
+ }
492
+ function getElement2(node) {
493
+ return node.nodeType === 1 ? node : node.parentElement;
494
+ }
495
+ function updateSelectionOnFocus(element) {
496
+ var _a;
497
+ const selection = element.ownerDocument.getSelection();
498
+ if (!(selection == null ? void 0 : selection.focusNode)) {
499
+ return;
500
+ }
501
+ if (hasOwnSelection(element)) {
502
+ const contenteditable = getContentEditable(selection.focusNode);
503
+ if (contenteditable) {
504
+ if (!selection.isCollapsed) {
505
+ const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
506
+ selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
507
+ }
508
+ } else {
509
+ selection.setBaseAndExtent(element, 0, element, 0);
510
+ }
511
+ }
512
+ }
513
+ function getInputRange(focusNode) {
514
+ var _a;
515
+ const typeAndSelection = getTargetTypeAndSelection(focusNode);
516
+ if (typeAndSelection.type === "input") {
517
+ return typeAndSelection.selection;
518
+ } else if (typeAndSelection.type === "contenteditable") {
519
+ return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
520
+ }
521
+ }
522
+ function setSelection({
523
+ focusNode,
524
+ focusOffset,
525
+ anchorNode = focusNode,
526
+ anchorOffset = focusOffset
527
+ }) {
528
+ var _a, _b;
529
+ const typeAndSelection = getTargetTypeAndSelection(focusNode);
530
+ if (typeAndSelection.type === "input") {
531
+ return setUISelection(focusNode, {
532
+ anchorOffset,
533
+ focusOffset
534
+ });
535
+ }
536
+ (_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
537
+ }
538
+
539
+ // src/utils/edit/editInputElement.ts
540
+ function editInputElement(config, element, {
541
+ newValue,
542
+ newSelection,
543
+ eventOverrides
544
+ }) {
545
+ const oldValue = element.value;
546
+ setUIValue(element, newValue);
547
+ setSelection({
548
+ focusNode: newSelection.node,
549
+ anchorOffset: newSelection.offset,
550
+ focusOffset: newSelection.offset
551
+ });
552
+ startTrackValue(element);
553
+ dispatchUIEvent(config, element, "input", eventOverrides);
554
+ const tracked = endTrackValue(element);
555
+ if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
556
+ setSelection({
557
+ focusNode: newSelection.node,
558
+ anchorOffset: newSelection.offset,
559
+ focusOffset: newSelection.offset
560
+ });
561
+ }
562
+ }
563
+
564
+ // src/utils/edit/getValue.ts
565
+ function getValue(element) {
566
+ if (!element) {
567
+ return null;
568
+ }
569
+ if (isContentEditable(element)) {
570
+ return element.textContent;
571
+ }
572
+ return getUIValue(element);
573
+ }
574
+
575
+ // src/utils/edit/maxLength.ts
576
+ var maxLengthSupportedTypes = /* @__PURE__ */ ((maxLengthSupportedTypes2) => {
577
+ maxLengthSupportedTypes2["email"] = "email";
578
+ maxLengthSupportedTypes2["password"] = "password";
579
+ maxLengthSupportedTypes2["search"] = "search";
580
+ maxLengthSupportedTypes2["telephone"] = "telephone";
581
+ maxLengthSupportedTypes2["text"] = "text";
582
+ maxLengthSupportedTypes2["url"] = "url";
583
+ return maxLengthSupportedTypes2;
584
+ })(maxLengthSupportedTypes || {});
585
+ function getSpaceUntilMaxLength(element) {
586
+ const value = getValue(element);
587
+ if (value === null) {
588
+ return void 0;
589
+ }
590
+ const maxLength = getSanitizedMaxLength(element);
591
+ return maxLength ? maxLength - value.length : void 0;
592
+ }
593
+ function getSanitizedMaxLength(element) {
594
+ var _a;
595
+ if (!supportsMaxLength(element)) {
596
+ return void 0;
597
+ }
598
+ const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
599
+ return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
600
+ }
601
+ function supportsMaxLength(element) {
602
+ return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
603
+ }
604
+
605
+ // src/utils/focus/cursor.ts
606
+ function getNextCursorPosition(node, offset, direction, inputType) {
607
+ if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) {
608
+ return { node, offset: offset + direction };
609
+ }
610
+ const nextNode = getNextCharacterContentNode(node, offset, direction);
611
+ if (nextNode) {
612
+ if (isTextNode(nextNode)) {
613
+ return {
614
+ node: nextNode,
615
+ offset: direction > 0 ? Math.min(1, nextNode.nodeValue.length) : Math.max(nextNode.nodeValue.length - 1, 0)
616
+ };
617
+ } else if (isElementType(nextNode, "br")) {
618
+ const nextPlusOne = getNextCharacterContentNode(nextNode, void 0, direction);
619
+ if (!nextPlusOne) {
620
+ if (direction < 0 && inputType === "deleteContentBackward") {
621
+ return {
622
+ node: nextNode.parentNode,
623
+ offset: getOffset(nextNode)
624
+ };
625
+ }
626
+ return void 0;
627
+ } else if (isTextNode(nextPlusOne)) {
628
+ return {
629
+ node: nextPlusOne,
630
+ offset: direction > 0 ? 0 : nextPlusOne.nodeValue.length
631
+ };
632
+ } else if (direction < 0 && isElementType(nextPlusOne, "br")) {
633
+ return {
634
+ node: nextNode.parentNode,
635
+ offset: getOffset(nextNode)
636
+ };
637
+ } else {
638
+ return {
639
+ node: nextPlusOne.parentNode,
640
+ offset: getOffset(nextPlusOne) + (direction > 0 ? 0 : 1)
641
+ };
642
+ }
643
+ } else {
644
+ return {
645
+ node: nextNode.parentNode,
646
+ offset: getOffset(nextNode) + (direction > 0 ? 1 : 0)
647
+ };
648
+ }
649
+ }
650
+ }
651
+ function getNextCharacterContentNode(node, offset, direction) {
652
+ const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
653
+ if (offset !== void 0 && isElement2(node) && nextOffset >= 0 && nextOffset < node.children.length) {
654
+ node = node.children[nextOffset];
655
+ }
656
+ return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
657
+ }
658
+ function isTreatedAsCharacterContent(node) {
659
+ if (isTextNode(node)) {
660
+ return true;
661
+ }
662
+ if (isElement2(node)) {
663
+ if (isElementType(node, ["input", "textarea"])) {
664
+ return node.type !== "hidden";
665
+ } else if (isElementType(node, "br")) {
666
+ return true;
667
+ }
668
+ }
669
+ return false;
670
+ }
671
+ function getOffset(node) {
672
+ let i = 0;
673
+ while (node.previousSibling) {
674
+ i++;
675
+ node = node.previousSibling;
676
+ }
677
+ return i;
678
+ }
679
+ function isElement2(node) {
680
+ return node.nodeType === 1;
681
+ }
682
+ function isTextNode(node) {
683
+ return node.nodeType === 3;
684
+ }
685
+ function walkNodes(node, direction, callback) {
686
+ var _a;
687
+ for (; ; ) {
688
+ const sibling = node[`${direction}Sibling`];
689
+ if (sibling) {
690
+ node = getDescendant(sibling, direction === "next" ? "first" : "last");
691
+ if (callback(node)) {
692
+ return node;
693
+ }
694
+ } else if (node.parentNode && (!isElement2(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
695
+ node = node.parentNode;
696
+ } else {
697
+ break;
698
+ }
699
+ }
700
+ }
701
+ function getDescendant(node, direction) {
702
+ while (node.hasChildNodes()) {
703
+ node = node[`${direction}Child`];
704
+ }
705
+ return node;
706
+ }
707
+
708
+ // src/utils/edit/prepareInput.ts
709
+ function prepareInput(config, data, element, inputType = "insertText") {
710
+ const inputRange = getInputRange(element);
711
+ if (!inputRange) {
712
+ return;
713
+ }
714
+ if ("startContainer" in inputRange) {
715
+ return {
716
+ commit: () => {
717
+ let del = false;
718
+ if (!inputRange.collapsed) {
719
+ del = true;
720
+ inputRange.deleteContents();
721
+ } else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
722
+ const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
723
+ if (nextPosition) {
724
+ del = true;
725
+ const delRange = inputRange.cloneRange();
726
+ if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
727
+ delRange.setStart(nextPosition.node, nextPosition.offset);
728
+ } else {
729
+ delRange.setEnd(nextPosition.node, nextPosition.offset);
730
+ }
731
+ delRange.deleteContents();
732
+ }
733
+ }
734
+ if (data) {
735
+ if (inputRange.endContainer.nodeType === 3) {
736
+ const offset = inputRange.endOffset;
737
+ inputRange.endContainer.insertData(offset, data);
738
+ inputRange.setStart(inputRange.endContainer, offset + data.length);
739
+ inputRange.setEnd(inputRange.endContainer, offset + data.length);
740
+ } else {
741
+ const text = element.ownerDocument.createTextNode(data);
742
+ inputRange.insertNode(text);
743
+ inputRange.setStart(text, data.length);
744
+ inputRange.setEnd(text, data.length);
745
+ }
746
+ }
747
+ if (del || data) {
748
+ dispatchUIEvent(config, element, "input", { inputType });
749
+ }
750
+ }
751
+ };
752
+ } else {
753
+ return {
754
+ getNewValue: () => calculateNewValue(data, element, inputRange, inputType).newValue,
755
+ commit: () => {
756
+ const { newValue, newOffset, oldValue } = calculateNewValue(data, element, inputRange, inputType);
757
+ if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
758
+ return;
759
+ }
760
+ editInputElement(config, element, {
761
+ newValue,
762
+ newSelection: {
763
+ node: element,
764
+ offset: newOffset
765
+ },
766
+ eventOverrides: {
767
+ inputType
768
+ }
769
+ });
770
+ }
771
+ };
772
+ }
773
+ }
774
+
775
+ // src/utils/edit/setFiles.ts
776
+ var fakeFiles = Symbol("files and value properties are mocked");
777
+ function setFiles(el, files) {
778
+ var _a;
779
+ (_a = el[fakeFiles]) == null ? void 0 : _a.restore();
780
+ const objectDescriptors = Object.getOwnPropertyDescriptors(el);
781
+ const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
782
+ function restore() {
783
+ Object.defineProperties(el, {
784
+ files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
785
+ value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
786
+ type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
787
+ });
788
+ }
789
+ el[fakeFiles] = { restore };
790
+ Object.defineProperties(el, {
791
+ files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
792
+ get: () => files
793
+ }),
794
+ value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
795
+ get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
796
+ set(v) {
797
+ var _a2;
798
+ if (v === "") {
799
+ restore();
800
+ } else {
801
+ (_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
802
+ }
803
+ }
804
+ }),
805
+ type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
806
+ set(v) {
807
+ if (v !== "file") {
808
+ restore();
809
+ el.type = v;
810
+ }
811
+ }
812
+ })
813
+ });
814
+ }
815
+
816
+ // src/utils/misc/eventWrapper.ts
817
+ var import_dom = require("@testing-library/dom");
818
+ function eventWrapper(cb) {
819
+ let result;
820
+ (0, import_dom.getConfig)().eventWrapper(() => {
821
+ result = cb();
822
+ });
823
+ return result;
824
+ }
825
+
826
+ // src/utils/misc/isDisabled.ts
827
+ function isDisabled(element) {
828
+ return Boolean(element && element.disabled);
829
+ }
830
+
831
+ // src/utils/focus/getActiveElement.ts
832
+ function getActiveElement(document2) {
833
+ const activeElement = document2.activeElement;
834
+ if (activeElement == null ? void 0 : activeElement.shadowRoot) {
835
+ return getActiveElement(activeElement.shadowRoot);
836
+ } else {
837
+ if (isDisabled(activeElement)) {
838
+ return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
839
+ }
840
+ return activeElement;
841
+ }
842
+ }
843
+
844
+ // src/utils/focus/selector.ts
845
+ var FOCUSABLE_SELECTOR = [
846
+ "input:not([type=hidden]):not([disabled])",
847
+ "button:not([disabled])",
848
+ "select:not([disabled])",
849
+ "textarea:not([disabled])",
850
+ '[contenteditable=""]',
851
+ '[contenteditable="true"]',
852
+ "a[href]",
853
+ "[tabindex]:not([disabled])"
854
+ ].join(", ");
855
+
856
+ // src/utils/focus/isFocusable.ts
857
+ function isFocusable(element) {
858
+ return element.matches(FOCUSABLE_SELECTOR);
859
+ }
860
+
861
+ // src/utils/focus/blur.ts
862
+ function blur(element) {
863
+ if (!isFocusable(element))
864
+ return;
865
+ const wasActive = getActiveElement(element.ownerDocument) === element;
866
+ if (!wasActive)
867
+ return;
868
+ eventWrapper(() => element.blur());
869
+ }
870
+
871
+ // src/utils/focus/copySelection.ts
872
+ function copySelection(target) {
873
+ const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
874
+ const dt = createDataTransfer();
875
+ for (const type3 in data) {
876
+ if (data[type3]) {
877
+ dt.setData(type3, data[type3]);
878
+ }
879
+ }
880
+ return dt;
881
+ }
882
+ function readSelectedValueFromInput(target) {
883
+ const sel = getUISelection(target);
884
+ const val = getUIValue(target);
885
+ return val.substring(sel.startOffset, sel.endOffset);
886
+ }
887
+
888
+ // src/utils/misc/findClosest.ts
889
+ function findClosest(element, callback) {
890
+ let el = element;
891
+ do {
892
+ if (callback(el)) {
893
+ return el;
894
+ }
895
+ el = el.parentElement;
896
+ } while (el && el !== element.ownerDocument.body);
897
+ return void 0;
898
+ }
899
+
900
+ // src/utils/focus/focus.ts
901
+ function focus(element) {
902
+ const target = findClosest(element, isFocusable);
903
+ const activeElement = getActiveElement(element.ownerDocument);
904
+ if ((target != null ? target : element.ownerDocument.body) === activeElement) {
905
+ return;
906
+ } else if (target) {
907
+ eventWrapper(() => target.focus());
908
+ } else {
909
+ eventWrapper(() => activeElement == null ? void 0 : activeElement.blur());
910
+ }
911
+ updateSelectionOnFocus(target != null ? target : element.ownerDocument.body);
912
+ }
913
+
914
+ // src/utils/misc/isVisible.ts
915
+ var import_helpers = require("@testing-library/dom/dist/helpers.js");
916
+ function isVisible(element) {
917
+ const window2 = (0, import_helpers.getWindowFromNode)(element);
918
+ for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
919
+ const { display, visibility } = window2.getComputedStyle(el);
920
+ if (display === "none") {
921
+ return false;
922
+ }
923
+ if (visibility === "hidden") {
924
+ return false;
925
+ }
926
+ }
927
+ return true;
928
+ }
929
+
930
+ // src/utils/focus/getTabDestination.ts
931
+ function getTabDestination(activeElement, shift) {
932
+ const document2 = activeElement.ownerDocument;
933
+ const focusableElements = document2.querySelectorAll(FOCUSABLE_SELECTOR);
934
+ const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex") !== "-1" && !isDisabled(el) && isVisible(el));
935
+ if (activeElement.getAttribute("tabindex") !== "-1") {
936
+ enabledElements.sort((a, b) => {
937
+ const i = Number(a.getAttribute("tabindex"));
938
+ const j = Number(b.getAttribute("tabindex"));
939
+ if (i === j) {
940
+ return 0;
941
+ } else if (i === 0) {
942
+ return 1;
943
+ } else if (j === 0) {
944
+ return -1;
945
+ }
946
+ return i - j;
947
+ });
948
+ }
949
+ const checkedRadio = {};
950
+ let prunedElements = [document2.body];
951
+ const activeRadioGroup = isElementType(activeElement, "input", {
952
+ type: "radio"
953
+ }) ? activeElement.name : void 0;
954
+ enabledElements.forEach((currentElement) => {
955
+ const el = currentElement;
956
+ if (isElementType(el, "input", { type: "radio" }) && el.name) {
957
+ if (el === activeElement) {
958
+ prunedElements.push(el);
959
+ return;
960
+ } else if (el.name === activeRadioGroup) {
961
+ return;
962
+ }
963
+ if (el.checked) {
964
+ prunedElements = prunedElements.filter((e) => !isElementType(e, "input", { type: "radio", name: el.name }));
965
+ prunedElements.push(el);
966
+ checkedRadio[el.name] = el;
967
+ return;
968
+ }
969
+ if (typeof checkedRadio[el.name] !== "undefined") {
970
+ return;
971
+ }
972
+ }
973
+ prunedElements.push(el);
974
+ });
975
+ const currentIndex = prunedElements.findIndex((el) => el === activeElement);
976
+ const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
977
+ const defaultIndex = shift ? prunedElements.length - 1 : 0;
978
+ return prunedElements[nextIndex] || prunedElements[defaultIndex];
979
+ }
980
+
981
+ // src/utils/focus/selectAll.ts
982
+ function selectAll(target) {
983
+ var _a;
984
+ if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
985
+ return setSelection({
986
+ focusNode: target,
987
+ anchorOffset: 0,
988
+ focusOffset: getUIValue(target).length
989
+ });
990
+ }
991
+ const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
992
+ setSelection({
993
+ focusNode,
994
+ anchorOffset: 0,
995
+ focusOffset: focusNode.childNodes.length
996
+ });
997
+ }
998
+ function isAllSelected(target) {
999
+ var _a;
1000
+ if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
1001
+ return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
1002
+ }
1003
+ const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
1004
+ const selection = target.ownerDocument.getSelection();
1005
+ return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
1006
+ }
1007
+
1008
+ // src/utils/keyboard/getKeyEventProps.ts
1009
+ function getKeyEventProps(keyDef) {
1010
+ return {
1011
+ key: keyDef.key,
1012
+ code: keyDef.code
1013
+ };
1014
+ }
1015
+
1016
+ // src/utils/keyboard/getUIEventModifiers.ts
1017
+ function getUIEventModifiers(keyboardState) {
1018
+ return {
1019
+ altKey: keyboardState.modifiers.Alt,
1020
+ ctrlKey: keyboardState.modifiers.Control,
1021
+ metaKey: keyboardState.modifiers.Meta,
1022
+ shiftKey: keyboardState.modifiers.Shift,
1023
+ modifierAltGraph: keyboardState.modifiers.AltGraph,
1024
+ modifierCapsLock: keyboardState.modifiers.CapsLock,
1025
+ modifierFn: keyboardState.modifiers.Fn,
1026
+ modifierFnLock: keyboardState.modifiers.FnLock,
1027
+ modifierNumLock: keyboardState.modifiers.NumLock,
1028
+ modifierScrollLock: keyboardState.modifiers.ScrollLock,
1029
+ modifierSymbol: keyboardState.modifiers.Symbol,
1030
+ modifierSymbolLock: keyboardState.modifiers.SymbolLock
1031
+ };
1032
+ }
1033
+
1034
+ // src/utils/keyDef/readNextDescriptor.ts
1035
+ var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
1036
+ bracketDict2["{"] = "}";
1037
+ bracketDict2["["] = "]";
1038
+ return bracketDict2;
1039
+ })(bracketDict || {});
1040
+ function readNextDescriptor(text) {
1041
+ let pos = 0;
1042
+ const startBracket = text[pos] in bracketDict ? text[pos] : "";
1043
+ pos += startBracket.length;
1044
+ const isEscapedChar = new RegExp(`^\\${startBracket}{2}`).test(text);
1045
+ const type3 = isEscapedChar ? "" : startBracket;
1046
+ return __spreadValues({
1047
+ type: type3
1048
+ }, type3 === "" ? readPrintableChar(text, pos) : readTag(text, pos, type3));
1049
+ }
1050
+ function readPrintableChar(text, pos) {
1051
+ const descriptor = text[pos];
1052
+ assertDescriptor(descriptor, text, pos);
1053
+ pos += descriptor.length;
1054
+ return {
1055
+ consumedLength: pos,
1056
+ descriptor,
1057
+ releasePrevious: false,
1058
+ releaseSelf: true,
1059
+ repeat: 1
1060
+ };
1061
+ }
1062
+ function readTag(text, pos, startBracket) {
1063
+ var _a, _b, _c;
1064
+ const releasePreviousModifier = text[pos] === "/" ? "/" : "";
1065
+ pos += releasePreviousModifier.length;
1066
+ const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
1067
+ pos += Number(escapedDescriptor);
1068
+ const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
1069
+ assertDescriptor(descriptor, text, pos);
1070
+ pos += descriptor.length;
1071
+ const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
1072
+ pos += repeatModifier.length;
1073
+ const releaseSelfModifier = text[pos] === "/" || !repeatModifier && text[pos] === ">" ? text[pos] : "";
1074
+ pos += releaseSelfModifier.length;
1075
+ const expectedEndBracket = bracketDict[startBracket];
1076
+ const endBracket = text[pos] === expectedEndBracket ? expectedEndBracket : "";
1077
+ if (!endBracket) {
1078
+ throw new Error(getErrorMessage([
1079
+ !repeatModifier && "repeat modifier",
1080
+ !releaseSelfModifier && "release modifier",
1081
+ `"${expectedEndBracket}"`
1082
+ ].filter(Boolean).join(" or "), text[pos], text));
1083
+ }
1084
+ pos += endBracket.length;
1085
+ return {
1086
+ consumedLength: pos,
1087
+ descriptor,
1088
+ releasePrevious: !!releasePreviousModifier,
1089
+ repeat: repeatModifier ? Math.max(Number(repeatModifier.substr(1)), 1) : 1,
1090
+ releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
1091
+ };
1092
+ }
1093
+ function assertDescriptor(descriptor, text, pos) {
1094
+ if (!descriptor) {
1095
+ throw new Error(getErrorMessage("key descriptor", text[pos], text));
1096
+ }
1097
+ }
1098
+ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
1099
+ if (releaseSelfModifier) {
1100
+ return releaseSelfModifier === "/";
1101
+ }
1102
+ if (repeatModifier) {
1103
+ return false;
1104
+ }
1105
+ }
1106
+ function getErrorMessage(expected, found, text) {
1107
+ return `Expected ${expected} but found "${found != null ? found : ""}" in "${text}"
1108
+ See https://github.com/testing-library/user-event/blob/main/README.md#keyboardtext-options
1109
+ for more information about how userEvent parses your input.`;
1110
+ }
1111
+
1112
+ // src/utils/misc/cloneEvent.ts
1113
+ function cloneEvent(event) {
1114
+ return new event.constructor(event.type, event);
1115
+ }
1116
+
1117
+ // src/utils/misc/getDocumentFromNode.ts
1118
+ function getDocumentFromNode(el) {
1119
+ return isDocument(el) ? el : el.ownerDocument;
1120
+ }
1121
+ function isDocument(node) {
1122
+ return node.nodeType === 9;
1123
+ }
1124
+
1125
+ // src/utils/misc/isDescendantOrSelf.ts
1126
+ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
1127
+ let el = potentialDescendant;
1128
+ do {
1129
+ if (el === potentialAncestor) {
1130
+ return true;
1131
+ }
1132
+ el = el.parentElement;
1133
+ } while (el);
1134
+ return false;
1135
+ }
1136
+
1137
+ // src/utils/misc/level.ts
1138
+ var Level = Symbol("Api level refs");
1139
+ function setLevelRef(config, level) {
1140
+ var _a;
1141
+ (_a = config[Level]) != null ? _a : config[Level] = {};
1142
+ config[Level][level] = {};
1143
+ }
1144
+ function getLevelRef(config, level) {
1145
+ var _a;
1146
+ return (_a = config[Level]) == null ? void 0 : _a[level];
1147
+ }
1148
+
1149
+ // src/utils/misc/wait.ts
1150
+ function wait(time) {
1151
+ return new Promise((resolve) => setTimeout(() => resolve(), time));
1152
+ }
1153
+
1154
+ // src/utils/misc/hasFormSubmit.ts
1155
+ var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
1156
+
1157
+ // src/utils/pointer/cssPointerEvents.ts
1158
+ var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
1159
+
1160
+ // src/keyboard/keyMap.ts
1161
+ var defaultKeyMap = [
1162
+ ..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
1163
+ ...")!@#$%^&*(".split("").map((c, i) => ({ code: `Digit${i}`, key: c, shiftKey: true })),
1164
+ ..."abcdefghijklmnopqrstuvwxyz".split("").map((c) => ({ code: `Key${c.toUpperCase()}`, key: c })),
1165
+ ..."ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((c) => ({ code: `Key${c}`, key: c, shiftKey: true })),
1166
+ { code: "Space", key: " " },
1167
+ { code: "AltLeft", key: "Alt", location: 1 /* LEFT */ },
1168
+ { code: "AltRight", key: "Alt", location: 2 /* RIGHT */ },
1169
+ {
1170
+ code: "ShiftLeft",
1171
+ key: "Shift",
1172
+ location: 1 /* LEFT */
1173
+ },
1174
+ {
1175
+ code: "ShiftRight",
1176
+ key: "Shift",
1177
+ location: 2 /* RIGHT */
1178
+ },
1179
+ {
1180
+ code: "ControlLeft",
1181
+ key: "Control",
1182
+ location: 1 /* LEFT */
1183
+ },
1184
+ {
1185
+ code: "ControlRight",
1186
+ key: "Control",
1187
+ location: 2 /* RIGHT */
1188
+ },
1189
+ { code: "MetaLeft", key: "Meta", location: 1 /* LEFT */ },
1190
+ {
1191
+ code: "MetaRight",
1192
+ key: "Meta",
1193
+ location: 2 /* RIGHT */
1194
+ },
1195
+ { code: "OSLeft", key: "OS", location: 1 /* LEFT */ },
1196
+ { code: "OSRight", key: "OS", location: 2 /* RIGHT */ },
1197
+ { code: "Tab", key: "Tab" },
1198
+ { code: "CapsLock", key: "CapsLock" },
1199
+ { code: "Backspace", key: "Backspace" },
1200
+ { code: "Enter", key: "Enter" },
1201
+ { code: "Escape", key: "Escape" },
1202
+ { code: "ArrowUp", key: "ArrowUp" },
1203
+ { code: "ArrowDown", key: "ArrowDown" },
1204
+ { code: "ArrowLeft", key: "ArrowLeft" },
1205
+ { code: "ArrowRight", key: "ArrowRight" },
1206
+ { code: "Home", key: "Home" },
1207
+ { code: "End", key: "End" },
1208
+ { code: "Delete", key: "Delete" },
1209
+ { code: "PageUp", key: "PageUp" },
1210
+ { code: "PageDown", key: "PageDown" },
1211
+ { code: "Fn", key: "Fn" },
1212
+ { code: "Symbol", key: "Symbol" },
1213
+ { code: "AltRight", key: "AltGraph" }
1214
+ ];
1215
+
1216
+ // src/pointer/keyMap.ts
1217
+ var defaultKeyMap2 = [
1218
+ { name: "MouseLeft", pointerType: "mouse", button: "primary" },
1219
+ { name: "MouseRight", pointerType: "mouse", button: "secondary" },
1220
+ { name: "MouseMiddle", pointerType: "mouse", button: "auxiliary" },
1221
+ { name: "TouchA", pointerType: "touch" },
1222
+ { name: "TouchB", pointerType: "touch" },
1223
+ { name: "TouchC", pointerType: "touch" }
1224
+ ];
1225
+
1226
+ // src/options.ts
1227
+ var PointerEventsCheckLevel = /* @__PURE__ */ ((PointerEventsCheckLevel2) => {
1228
+ PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachTrigger"] = 4] = "EachTrigger";
1229
+ PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachApiCall"] = 2] = "EachApiCall";
1230
+ PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachTarget"] = 1] = "EachTarget";
1231
+ PointerEventsCheckLevel2[PointerEventsCheckLevel2["Never"] = 0] = "Never";
1232
+ return PointerEventsCheckLevel2;
1233
+ })(PointerEventsCheckLevel || {});
1234
+ var defaultOptionsDirect = {
1235
+ applyAccept: true,
1236
+ autoModify: true,
1237
+ delay: 0,
1238
+ document: global.document,
1239
+ keyboardMap: defaultKeyMap,
1240
+ pointerMap: defaultKeyMap2,
1241
+ pointerEventsCheck: 2 /* EachApiCall */,
1242
+ skipAutoClose: false,
1243
+ skipClick: false,
1244
+ skipHover: false,
1245
+ writeToClipboard: false
1246
+ };
1247
+ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
1248
+ writeToClipboard: true
1249
+ });
1250
+
1251
+ // src/utils/pointer/cssPointerEvents.ts
1252
+ function hasPointerEvents(element) {
1253
+ const window2 = (0, import_helpers2.getWindowFromNode)(element);
1254
+ for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1255
+ const pointerEvents = window2.getComputedStyle(el).pointerEvents;
1256
+ if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
1257
+ return pointerEvents !== "none";
1258
+ }
1259
+ }
1260
+ return true;
1261
+ }
1262
+ var PointerEventsCheck = Symbol("Last check for pointer-events");
1263
+ function assertPointerEvents(config, element) {
1264
+ const lastCheck = element[PointerEventsCheck];
1265
+ const needsCheck = config.pointerEventsCheck !== 0 /* Never */ && (!lastCheck || hasBitFlag(config.pointerEventsCheck, 2 /* EachApiCall */) && lastCheck[1 /* Call */] !== getLevelRef(config, 1 /* Call */) || hasBitFlag(config.pointerEventsCheck, 4 /* EachTrigger */) && lastCheck[2 /* Trigger */] !== getLevelRef(config, 2 /* Trigger */));
1266
+ if (!needsCheck) {
1267
+ return;
1268
+ }
1269
+ const result = hasPointerEvents(element);
1270
+ element[PointerEventsCheck] = {
1271
+ [1 /* Call */]: getLevelRef(config, 1 /* Call */),
1272
+ [2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
1273
+ result
1274
+ };
1275
+ if (!result) {
1276
+ throw new Error('Unable to perform pointer interaction as the element has or inherits pointer-events set to "none".');
1277
+ }
1278
+ }
1279
+ function hasBitFlag(conf, flag) {
1280
+ return (conf & flag) > 0;
1281
+ }
1282
+
1283
+ // src/utils/pointer/mouseButtons.ts
1284
+ var MouseButton = {
1285
+ primary: 0,
1286
+ secondary: 1,
1287
+ auxiliary: 2,
1288
+ back: 3,
1289
+ X1: 3,
1290
+ forward: 4,
1291
+ X2: 4
1292
+ };
1293
+ var MouseButtonFlip = {
1294
+ auxiliary: 1,
1295
+ secondary: 2,
1296
+ 1: 2,
1297
+ 2: 1
1298
+ };
1299
+ function getMouseButton(button) {
1300
+ if (button in MouseButtonFlip) {
1301
+ return MouseButtonFlip[button];
1302
+ }
1303
+ return typeof button === "number" ? button : MouseButton[button];
1304
+ }
1305
+ function getMouseButtons(...buttons) {
1306
+ let v = 0;
1307
+ for (const t of buttons) {
1308
+ const pos = typeof t === "number" ? t : MouseButton[t];
1309
+ v |= 2 ** pos;
1310
+ }
1311
+ return v;
1312
+ }
1313
+
1314
+ // src/event/createEvent.ts
1315
+ var import_dom2 = require("@testing-library/dom");
1316
+ var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
1317
+
1318
+ // src/event/eventTypes.ts
1319
+ var import_event_map = require("@testing-library/dom/dist/event-map.js");
1320
+ var eventKeys = Object.fromEntries(Object.keys(import_event_map.eventMap).map((k) => [k.toLowerCase(), k]));
1321
+ function getEventClass(type3) {
1322
+ return import_event_map.eventMap[eventKeys[type3]].EventType;
1323
+ }
1324
+ var mouseEvents = ["MouseEvent", "PointerEvent"];
1325
+ function isMouseEvent(type3) {
1326
+ return mouseEvents.includes(getEventClass(type3));
1327
+ }
1328
+ function isKeyboardEvent(type3) {
1329
+ return getEventClass(type3) === "KeyboardEvent";
1330
+ }
1331
+
1332
+ // src/event/createEvent.ts
1333
+ function createEvent(type3, target, init) {
1334
+ const eventKey = Object.keys(import_event_map2.eventMap).find((k) => k.toLowerCase() === type3);
1335
+ const event = import_dom2.createEvent[eventKey](target, init);
1336
+ if (isMouseEvent(type3) && init) {
1337
+ assignPositionInit(event, init);
1338
+ assignPointerInit(event, init);
1339
+ }
1340
+ return event;
1341
+ }
1342
+ function assignProps(obj, props) {
1343
+ for (const [key, value] of Object.entries(props)) {
1344
+ Object.defineProperty(obj, key, { get: () => value });
1345
+ }
1346
+ }
1347
+ function assignPositionInit(obj, {
1348
+ x,
1349
+ y,
1350
+ clientX,
1351
+ clientY,
1352
+ offsetX,
1353
+ offsetY,
1354
+ pageX,
1355
+ pageY,
1356
+ screenX,
1357
+ screenY
1358
+ }) {
1359
+ var _a, _b, _c, _d;
1360
+ assignProps(obj, {
1361
+ x: (_a = x != null ? x : clientX) != null ? _a : 0,
1362
+ y: (_b = y != null ? y : clientY) != null ? _b : 0,
1363
+ clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
1364
+ clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
1365
+ offsetX: offsetX != null ? offsetX : 0,
1366
+ offsetY: offsetY != null ? offsetY : 0,
1367
+ pageX: pageX != null ? pageX : 0,
1368
+ pageY: pageY != null ? pageY : 0,
1369
+ screenX: screenX != null ? screenX : 0,
1370
+ screenY: screenY != null ? screenY : 0
1371
+ });
1372
+ }
1373
+ function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
1374
+ assignProps(obj, {
1375
+ isPrimary,
1376
+ pointerId,
1377
+ pointerType
1378
+ });
1379
+ }
1380
+
1381
+ // src/event/behavior/registry.ts
1382
+ var behavior = {};
1383
+
1384
+ // src/event/behavior/click.ts
1385
+ behavior.click = (event, target, config) => {
1386
+ const context = target.closest("button,input,label,textarea");
1387
+ const control = context && isElementType(context, "label") && context.control;
1388
+ if (control) {
1389
+ return () => {
1390
+ if (isFocusable(control)) {
1391
+ focus(control);
1392
+ }
1393
+ dispatchEvent(config, control, cloneEvent(event));
1394
+ };
1395
+ } else if (isElementType(target, "input", { type: "file" })) {
1396
+ return () => {
1397
+ blur(target);
1398
+ target.dispatchEvent(new Event("fileDialog"));
1399
+ focus(target);
1400
+ };
1401
+ }
1402
+ };
1403
+
1404
+ // src/event/dispatchEvent.ts
1405
+ function dispatchEvent(config, target, event) {
1406
+ var _a, _b;
1407
+ const type3 = event.type;
1408
+ const behaviorImplementation = (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
1409
+ if (behaviorImplementation) {
1410
+ event.preventDefault();
1411
+ let defaultPrevented = false;
1412
+ Object.defineProperty(event, "defaultPrevented", {
1413
+ get: () => defaultPrevented
1414
+ });
1415
+ Object.defineProperty(event, "preventDefault", {
1416
+ value: () => {
1417
+ defaultPrevented = event.cancelable;
1418
+ }
1419
+ });
1420
+ target.dispatchEvent(event);
1421
+ if (!defaultPrevented) {
1422
+ behaviorImplementation();
1423
+ }
1424
+ return !defaultPrevented;
1425
+ }
1426
+ return target.dispatchEvent(event);
1427
+ }
1428
+
1429
+ // src/event/wrapEvent.ts
1430
+ var import_dom3 = require("@testing-library/dom");
1431
+ function wrapEvent(cb, _element) {
1432
+ return (0, import_dom3.getConfig)().eventWrapper(cb);
1433
+ }
1434
+
1435
+ // src/event/index.ts
1436
+ function dispatchUIEvent(config, target, type3, init) {
1437
+ if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
1438
+ init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
1439
+ }
1440
+ const event = createEvent(type3, target, init);
1441
+ return wrapEvent(() => dispatchEvent(config, target, event), target);
1442
+ }
1443
+ function bindDispatchUIEvent(config) {
1444
+ return dispatchUIEvent.bind(void 0, config);
1445
+ }
1446
+
1447
+ // src/document/interceptor.ts
1448
+ var Interceptor = Symbol("Interceptor for programmatical calls");
1449
+ function prepareInterceptor(element, propName, interceptorImpl) {
1450
+ const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
1451
+ const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
1452
+ const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
1453
+ if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
1454
+ return;
1455
+ }
1456
+ function intercept(...args) {
1457
+ const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
1458
+ const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
1459
+ if (target === "set") {
1460
+ realFunc.call(this, realArgs);
1461
+ } else {
1462
+ realFunc.call(this, ...realArgs);
1463
+ }
1464
+ }
1465
+ ;
1466
+ intercept[Interceptor] = Interceptor;
1467
+ Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
1468
+ [target]: intercept
1469
+ }));
1470
+ }
1471
+
1472
+ // src/document/selection.ts
1473
+ var UISelection = Symbol("Displayed selection in UI");
1474
+ function prepareSelectionInterceptor(element) {
1475
+ prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
1476
+ const isUI = start && typeof start === "object" && start[UISelection];
1477
+ if (!isUI) {
1478
+ this[UISelection] = void 0;
1479
+ }
1480
+ return {
1481
+ realArgs: [Number(start), end, direction]
1482
+ };
1483
+ });
1484
+ prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
1485
+ this[UISelection] = void 0;
1486
+ return { realArgs: v };
1487
+ });
1488
+ prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
1489
+ this[UISelection] = void 0;
1490
+ return { realArgs: v };
1491
+ });
1492
+ }
1493
+ function setUISelection(element, {
1494
+ focusOffset: focusOffsetParam,
1495
+ anchorOffset: anchorOffsetParam = focusOffsetParam
1496
+ }, mode = "replace") {
1497
+ const valueLength = getUIValue(element).length;
1498
+ const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
1499
+ const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
1500
+ const focusOffset = sanitizeOffset(focusOffsetParam);
1501
+ const startOffset = Math.min(anchorOffset, focusOffset);
1502
+ const endOffset = Math.max(anchorOffset, focusOffset);
1503
+ element[UISelection] = {
1504
+ anchorOffset,
1505
+ focusOffset
1506
+ };
1507
+ if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
1508
+ return;
1509
+ }
1510
+ const startObj = new Number(startOffset);
1511
+ startObj[UISelection] = UISelection;
1512
+ try {
1513
+ element.setSelectionRange(startObj, endOffset);
1514
+ } catch {
1515
+ }
1516
+ }
1517
+ function getUISelection(element) {
1518
+ var _a, _b, _c;
1519
+ const sel = (_c = element[UISelection]) != null ? _c : {
1520
+ anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
1521
+ focusOffset: (_b = element.selectionEnd) != null ? _b : 0
1522
+ };
1523
+ return __spreadProps(__spreadValues({}, sel), {
1524
+ startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
1525
+ endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
1526
+ });
1527
+ }
1528
+ function clearUISelection(element) {
1529
+ element[UISelection] = void 0;
1530
+ }
1531
+
1532
+ // src/document/value.ts
1533
+ var UIValue = Symbol("Displayed value in UI");
1534
+ var InitialValue = Symbol("Initial value to compare on blur");
1535
+ var TrackChanges = Symbol("Track programmatic changes for React workaround");
1536
+ function valueInterceptor(v) {
1537
+ const isUI = typeof v === "object" && v[UIValue];
1538
+ this[UIValue] = isUI ? String(v) : void 0;
1539
+ if (!isUI) {
1540
+ trackValue(this, String(v));
1541
+ this[InitialValue] = String(v);
1542
+ clearUISelection(this);
1543
+ }
1544
+ return {
1545
+ applyNative: !!isUI,
1546
+ realArgs: String(v)
1547
+ };
1548
+ }
1549
+ function prepareValueInterceptor(element) {
1550
+ prepareInterceptor(element, "value", valueInterceptor);
1551
+ }
1552
+ function setUIValue(element, value) {
1553
+ element.value = {
1554
+ [UIValue]: UIValue,
1555
+ toString: () => value
1556
+ };
1557
+ }
1558
+ function getUIValue(element) {
1559
+ return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
1560
+ }
1561
+ function setInitialValue(element) {
1562
+ element[InitialValue] = element.value;
1563
+ }
1564
+ function getInitialValue(element) {
1565
+ return element[InitialValue];
1566
+ }
1567
+ function startTrackValue(element) {
1568
+ element[TrackChanges] = [];
1569
+ }
1570
+ function trackValue(element, v) {
1571
+ var _a;
1572
+ (_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
1573
+ }
1574
+ function endTrackValue(element) {
1575
+ const tracked = element[TrackChanges];
1576
+ element[TrackChanges] = void 0;
1577
+ return tracked;
1578
+ }
1579
+
1580
+ // src/document/index.ts
1581
+ var isPrepared = Symbol("Node prepared with document state workarounds");
1582
+ function prepareDocument(document2) {
1583
+ if (document2[isPrepared]) {
1584
+ return;
1585
+ }
1586
+ document2.addEventListener("focus", (e) => {
1587
+ const el = e.target;
1588
+ prepareElement(el);
1589
+ }, {
1590
+ capture: true,
1591
+ passive: true
1592
+ });
1593
+ if (document2.activeElement) {
1594
+ prepareElement(document2.activeElement);
1595
+ }
1596
+ document2.addEventListener("blur", (e) => {
1597
+ const el = e.target;
1598
+ const initialValue = getInitialValue(el);
1599
+ if (typeof initialValue === "string" && el.value !== initialValue) {
1600
+ dispatchUIEvent({}, el, "change");
1601
+ }
1602
+ }, {
1603
+ capture: true,
1604
+ passive: true
1605
+ });
1606
+ document2[isPrepared] = isPrepared;
1607
+ }
1608
+ function prepareElement(el) {
1609
+ if ("value" in el) {
1610
+ setInitialValue(el);
1611
+ }
1612
+ if (el[isPrepared]) {
1613
+ return;
1614
+ }
1615
+ if ("value" in el) {
1616
+ prepareValueInterceptor(el);
1617
+ prepareSelectionInterceptor(el);
1618
+ }
1619
+ el[isPrepared] = isPrepared;
1620
+ }
1621
+
1622
+ // src/keyboard/plugins/arrow.ts
1623
+ var keydownBehavior = [
1624
+ {
1625
+ matches: (keyDef) => keyDef.key === "ArrowLeft" || keyDef.key === "ArrowRight",
1626
+ handle: (keyDef, element) => {
1627
+ if (hasOwnSelection(element)) {
1628
+ const selection = getUISelection(element);
1629
+ setSelection({
1630
+ focusNode: element,
1631
+ focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
1632
+ });
1633
+ } else {
1634
+ const selection = element.ownerDocument.getSelection();
1635
+ if (!selection) {
1636
+ return;
1637
+ }
1638
+ if (selection.isCollapsed) {
1639
+ const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, keyDef.key === "ArrowLeft" ? -1 : 1);
1640
+ if (nextPosition) {
1641
+ setSelection({
1642
+ focusNode: nextPosition.node,
1643
+ focusOffset: nextPosition.offset
1644
+ });
1645
+ }
1646
+ } else {
1647
+ selection[keyDef.key === "ArrowLeft" ? "collapseToStart" : "collapseToEnd"]();
1648
+ }
1649
+ }
1650
+ }
1651
+ }
1652
+ ];
1653
+
1654
+ // src/keyboard/plugins/control.ts
1655
+ var keydownBehavior2 = [
1656
+ {
1657
+ matches: (keyDef, element) => (keyDef.key === "Home" || keyDef.key === "End") && (isElementType(element, ["input", "textarea"]) || isContentEditable(element)),
1658
+ handle: (keyDef, element) => {
1659
+ var _a, _b;
1660
+ if (keyDef.key === "Home") {
1661
+ setSelectionRange(element, 0, 0);
1662
+ } else {
1663
+ const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
1664
+ setSelectionRange(element, newPos, newPos);
1665
+ }
1666
+ }
1667
+ },
1668
+ {
1669
+ matches: (keyDef, element) => (keyDef.key === "PageUp" || keyDef.key === "PageDown") && isElementType(element, ["input"]),
1670
+ handle: (keyDef, element) => {
1671
+ var _a, _b;
1672
+ if (keyDef.key === "PageUp") {
1673
+ setSelectionRange(element, 0, 0);
1674
+ } else {
1675
+ const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
1676
+ setSelectionRange(element, newPos, newPos);
1677
+ }
1678
+ }
1679
+ },
1680
+ {
1681
+ matches: (keyDef, element) => keyDef.key === "Delete" && isEditable(element),
1682
+ handle: (keDef, element, config) => {
1683
+ var _a;
1684
+ (_a = prepareInput(config, "", element, "deleteContentForward")) == null ? void 0 : _a.commit();
1685
+ }
1686
+ }
1687
+ ];
1688
+
1689
+ // src/keyboard/shared/fireChangeForInputTimeIfValid.ts
1690
+ function fireChangeForInputTimeIfValid(config, el, prevValue, timeNewEntry) {
1691
+ if (isValidInputTimeValue(el, timeNewEntry) && prevValue !== timeNewEntry) {
1692
+ setUIValue(el, timeNewEntry);
1693
+ dispatchUIEvent(config, el, "change");
1694
+ }
1695
+ }
1696
+
1697
+ // src/keyboard/plugins/character.ts
1698
+ var keypressBehavior = [
1699
+ {
1700
+ matches: (keyDef, element) => {
1701
+ var _a;
1702
+ return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
1703
+ },
1704
+ handle: (keyDef, element, config) => {
1705
+ var _a;
1706
+ let newEntry = keyDef.key;
1707
+ const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
1708
+ const timeNewEntry = buildTimeValue(textToBeTyped);
1709
+ if (isValidInputTimeValue(element, timeNewEntry)) {
1710
+ newEntry = timeNewEntry;
1711
+ }
1712
+ const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
1713
+ const prevValue = getValue(element);
1714
+ if (prevValue !== newValue) {
1715
+ editInputElement(config, element, {
1716
+ newValue,
1717
+ newSelection: {
1718
+ node: element,
1719
+ offset: newOffset
1720
+ },
1721
+ eventOverrides: {
1722
+ data: keyDef.key,
1723
+ inputType: "insertText"
1724
+ }
1725
+ });
1726
+ }
1727
+ fireChangeForInputTimeIfValid(config, element, prevValue, timeNewEntry);
1728
+ config.keyboardState.carryValue = textToBeTyped;
1729
+ }
1730
+ },
1731
+ {
1732
+ matches: (keyDef, element) => {
1733
+ var _a;
1734
+ return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
1735
+ },
1736
+ handle: (keyDef, element, config) => {
1737
+ var _a;
1738
+ let newEntry = keyDef.key;
1739
+ const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
1740
+ const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
1741
+ if (isValidToBeTyped) {
1742
+ newEntry = textToBeTyped;
1743
+ }
1744
+ const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
1745
+ const prevValue = getValue(element);
1746
+ if (prevValue !== newValue) {
1747
+ editInputElement(config, element, {
1748
+ newValue,
1749
+ newSelection: {
1750
+ node: element,
1751
+ offset: newOffset
1752
+ },
1753
+ eventOverrides: {
1754
+ data: keyDef.key,
1755
+ inputType: "insertText"
1756
+ }
1757
+ });
1758
+ }
1759
+ if (isValidToBeTyped) {
1760
+ setUIValue(element, textToBeTyped);
1761
+ dispatchUIEvent(config, element, "change");
1762
+ }
1763
+ config.keyboardState.carryValue = textToBeTyped;
1764
+ }
1765
+ },
1766
+ {
1767
+ matches: (keyDef, element) => {
1768
+ var _a;
1769
+ return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
1770
+ },
1771
+ handle: (keyDef, element, config) => {
1772
+ var _a, _b;
1773
+ if (!/[\d.\-e]/.test(keyDef.key)) {
1774
+ return;
1775
+ }
1776
+ const { getNewValue, commit } = prepareInput(config, keyDef.key, element);
1777
+ const newValue = getNewValue();
1778
+ const valueParts = newValue.split("e", 2);
1779
+ if (Number((_a = newValue.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = newValue.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1])) {
1780
+ return;
1781
+ }
1782
+ commit();
1783
+ }
1784
+ },
1785
+ {
1786
+ matches: (keyDef, element) => {
1787
+ var _a;
1788
+ return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
1789
+ },
1790
+ handle: (keyDef, element, config) => {
1791
+ var _a;
1792
+ (_a = prepareInput(config, keyDef.key, element)) == null ? void 0 : _a.commit();
1793
+ }
1794
+ },
1795
+ {
1796
+ matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
1797
+ handle: (keyDef, element, config) => {
1798
+ var _a;
1799
+ (_a = prepareInput(config, "\n", element, isContentEditable(element) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
1800
+ }
1801
+ }
1802
+ ];
1803
+
1804
+ // src/keyboard/plugins/functional.ts
1805
+ var keydownBehavior3 = [
1806
+ {
1807
+ matches: (keyDef, element) => keyDef.key === "Backspace" && isEditable(element),
1808
+ handle: (keyDef, element, config) => {
1809
+ var _a;
1810
+ (_a = prepareInput(config, "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
1811
+ }
1812
+ },
1813
+ {
1814
+ matches: (keyDef) => keyDef.key === "Tab",
1815
+ handle: (keyDef, element, { keyboardState }) => {
1816
+ const dest = getTabDestination(element, keyboardState.modifiers.Shift);
1817
+ if (dest === element.ownerDocument.body) {
1818
+ blur(element);
1819
+ } else {
1820
+ focus(dest);
1821
+ if (isElementType(dest, ["input", "textarea"])) {
1822
+ setUISelection(dest, {
1823
+ anchorOffset: 0,
1824
+ focusOffset: dest.value.length
1825
+ });
1826
+ }
1827
+ }
1828
+ }
1829
+ }
1830
+ ];
1831
+ var keypressBehavior2 = [
1832
+ {
1833
+ matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input") && ["checkbox", "radio"].includes(element.type),
1834
+ handle: (keyDef, element, config) => {
1835
+ const form = element.form;
1836
+ if (hasFormSubmit(form)) {
1837
+ dispatchUIEvent(config, form, "submit");
1838
+ }
1839
+ }
1840
+ },
1841
+ {
1842
+ matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
1843
+ handle: (keyDef, element, config) => {
1844
+ dispatchUIEvent(config, element, "click");
1845
+ }
1846
+ },
1847
+ {
1848
+ matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
1849
+ handle: (keyDef, element, config) => {
1850
+ const form = element.form;
1851
+ if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
1852
+ dispatchUIEvent(config, form, "submit");
1853
+ }
1854
+ }
1855
+ }
1856
+ ];
1857
+ var keyupBehavior = [
1858
+ {
1859
+ matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
1860
+ handle: (keyDef, element, config) => {
1861
+ dispatchUIEvent(config, element, "click");
1862
+ }
1863
+ }
1864
+ ];
1865
+
1866
+ // src/keyboard/plugins/combination.ts
1867
+ var keydownBehavior4 = [
1868
+ {
1869
+ matches: (keyDef, element, { keyboardState }) => keyDef.code === "KeyA" && keyboardState.modifiers.Control,
1870
+ handle: (keyDef, element) => selectAll(element)
1871
+ }
1872
+ ];
1873
+
1874
+ // src/keyboard/plugins/modifiers.ts
1875
+ var modifierKeys = [
1876
+ "Alt",
1877
+ "AltGraph",
1878
+ "Control",
1879
+ "Fn",
1880
+ "Meta",
1881
+ "Shift",
1882
+ "Symbol"
1883
+ ];
1884
+ var modifierLocks = [
1885
+ "CapsLock",
1886
+ "FnLock",
1887
+ "NumLock",
1888
+ "ScrollLock",
1889
+ "SymbolLock"
1890
+ ];
1891
+ var preKeydownBehavior = [
1892
+ {
1893
+ matches: (keyDef) => modifierKeys.includes(keyDef.key),
1894
+ handle: (keyDef, element, config) => {
1895
+ var _a;
1896
+ config.keyboardState.modifiers[keyDef.key] = true;
1897
+ if (keyDef.key === "AltGraph") {
1898
+ const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1899
+ dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
1900
+ }
1901
+ }
1902
+ },
1903
+ {
1904
+ matches: (keyDef) => modifierLocks.includes(keyDef.key),
1905
+ handle: (keyDef, element, { keyboardState }) => {
1906
+ const key = keyDef.key;
1907
+ keyboardState.modifierPhase[key] = keyboardState.modifiers[key];
1908
+ if (!keyboardState.modifierPhase[key]) {
1909
+ keyboardState.modifiers[key] = true;
1910
+ }
1911
+ }
1912
+ }
1913
+ ];
1914
+ var preKeyupBehavior = [
1915
+ {
1916
+ matches: (keyDef) => modifierKeys.includes(keyDef.key),
1917
+ handle: (keyDef, element, { keyboardState }) => {
1918
+ keyboardState.modifiers[keyDef.key] = false;
1919
+ }
1920
+ },
1921
+ {
1922
+ matches: (keyDef) => modifierLocks.includes(keyDef.key),
1923
+ handle: (keyDef, element, { keyboardState }) => {
1924
+ const key = keyDef.key;
1925
+ if (keyboardState.modifierPhase[key]) {
1926
+ keyboardState.modifiers[key] = false;
1927
+ }
1928
+ }
1929
+ }
1930
+ ];
1931
+ var postKeyupBehavior = [
1932
+ {
1933
+ matches: (keyDef) => keyDef.key === "AltGraph",
1934
+ handle: (keyDef, element, config) => {
1935
+ var _a;
1936
+ const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
1937
+ dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
1938
+ }
1939
+ }
1940
+ ];
1941
+
1942
+ // src/keyboard/plugins/index.ts
1943
+ var preKeydownBehavior2 = [
1944
+ ...preKeydownBehavior
1945
+ ];
1946
+ var keydownBehavior5 = [
1947
+ ...keydownBehavior,
1948
+ ...keydownBehavior2,
1949
+ ...keydownBehavior3,
1950
+ ...keydownBehavior4
1951
+ ];
1952
+ var keypressBehavior3 = [
1953
+ ...keypressBehavior2,
1954
+ ...keypressBehavior
1955
+ ];
1956
+ var preKeyupBehavior2 = [
1957
+ ...preKeyupBehavior
1958
+ ];
1959
+ var keyupBehavior2 = [...keyupBehavior];
1960
+ var postKeyupBehavior2 = [
1961
+ ...postKeyupBehavior
1962
+ ];
1963
+
1964
+ // src/keyboard/keyboardAction.ts
1965
+ async function keyboardAction(config, actions) {
1966
+ for (let i = 0; i < actions.length; i++) {
1967
+ await keyboardKeyAction(config, actions[i]);
1968
+ if (typeof config.delay === "number" && i < actions.length - 1) {
1969
+ await wait(config.delay);
1970
+ }
1971
+ }
1972
+ }
1973
+ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf, repeat }) {
1974
+ const { document: document2, keyboardState, delay } = config;
1975
+ const getCurrentElement = () => getActive(document2);
1976
+ const pressed = keyboardState.pressed.find((p) => p.keyDef === keyDef);
1977
+ if (pressed) {
1978
+ await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
1979
+ }
1980
+ if (!releasePrevious) {
1981
+ let unpreventedDefault = true;
1982
+ for (let i = 1; i <= repeat; i++) {
1983
+ unpreventedDefault = await keydown(keyDef, getCurrentElement, config);
1984
+ if (unpreventedDefault && hasKeyPress(keyDef, config)) {
1985
+ await keypress(keyDef, getCurrentElement, config);
1986
+ }
1987
+ if (typeof delay === "number" && i < repeat) {
1988
+ await wait(delay);
1989
+ }
1990
+ }
1991
+ if (releaseSelf) {
1992
+ await keyup(keyDef, getCurrentElement, config, unpreventedDefault);
1993
+ }
1994
+ }
1995
+ }
1996
+ function getActive(document2) {
1997
+ var _a;
1998
+ return (_a = getActiveElement(document2)) != null ? _a : document2.body;
1999
+ }
2000
+ async function releaseAllKeys(config) {
2001
+ const getCurrentElement = () => getActive(config.document);
2002
+ for (const k of config.keyboardState.pressed) {
2003
+ await keyup(k.keyDef, getCurrentElement, config, k.unpreventedDefault);
2004
+ }
2005
+ }
2006
+ async function keydown(keyDef, getCurrentElement, config) {
2007
+ const element = getCurrentElement();
2008
+ if (element !== config.keyboardState.activeElement) {
2009
+ config.keyboardState.carryValue = void 0;
2010
+ config.keyboardState.carryChar = "";
2011
+ }
2012
+ config.keyboardState.activeElement = element;
2013
+ applyPlugins(preKeydownBehavior2, keyDef, element, config);
2014
+ const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
2015
+ config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
2016
+ if (unpreventedDefault) {
2017
+ applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
2018
+ }
2019
+ return unpreventedDefault;
2020
+ }
2021
+ async function keypress(keyDef, getCurrentElement, config) {
2022
+ const element = getCurrentElement();
2023
+ const unpreventedDefault = dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
2024
+ charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
2025
+ }));
2026
+ if (unpreventedDefault) {
2027
+ applyPlugins(keypressBehavior3, keyDef, getCurrentElement(), config);
2028
+ }
2029
+ }
2030
+ async function keyup(keyDef, getCurrentElement, config, unprevented) {
2031
+ const element = getCurrentElement();
2032
+ applyPlugins(preKeyupBehavior2, keyDef, element, config);
2033
+ const unpreventedDefault = dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef));
2034
+ if (unprevented && unpreventedDefault) {
2035
+ applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
2036
+ }
2037
+ config.keyboardState.pressed = config.keyboardState.pressed.filter((k) => k.keyDef !== keyDef);
2038
+ applyPlugins(postKeyupBehavior2, keyDef, element, config);
2039
+ }
2040
+ function applyPlugins(pluginCollection, keyDef, element, config) {
2041
+ const plugin = pluginCollection.find((p) => p.matches(keyDef, element, config));
2042
+ if (plugin) {
2043
+ plugin.handle(keyDef, element, config);
2044
+ }
2045
+ return !!plugin;
2046
+ }
2047
+ function hasKeyPress(keyDef, config) {
2048
+ var _a;
2049
+ return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
2050
+ }
2051
+
2052
+ // src/keyboard/parseKeyDef.ts
2053
+ function parseKeyDef(keyboardMap, text) {
2054
+ var _a;
2055
+ const defs = [];
2056
+ do {
2057
+ const {
2058
+ type: type3,
2059
+ descriptor,
2060
+ consumedLength,
2061
+ releasePrevious,
2062
+ releaseSelf = true,
2063
+ repeat
2064
+ } = readNextDescriptor(text);
2065
+ const keyDef = (_a = keyboardMap.find((def) => {
2066
+ var _a2, _b;
2067
+ if (type3 === "[") {
2068
+ return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
2069
+ } else if (type3 === "{") {
2070
+ return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
2071
+ }
2072
+ return def.key === descriptor;
2073
+ })) != null ? _a : {
2074
+ key: "Unknown",
2075
+ code: "Unknown",
2076
+ [type3 === "[" ? "code" : "key"]: descriptor
2077
+ };
2078
+ defs.push({ keyDef, releasePrevious, releaseSelf, repeat });
2079
+ text = text.slice(consumedLength);
2080
+ } while (text);
2081
+ return defs;
2082
+ }
2083
+
2084
+ // src/keyboard/index.ts
2085
+ async function keyboard(text) {
2086
+ const actions = parseKeyDef(this[Config].keyboardMap, text);
2087
+ return keyboardAction(this[Config], actions);
2088
+ }
2089
+ function createKeyboardState() {
2090
+ return {
2091
+ activeElement: null,
2092
+ pressed: [],
2093
+ carryChar: "",
2094
+ modifiers: {
2095
+ Alt: false,
2096
+ AltGraph: false,
2097
+ Control: false,
2098
+ CapsLock: false,
2099
+ Fn: false,
2100
+ FnLock: false,
2101
+ Meta: false,
2102
+ NumLock: false,
2103
+ ScrollLock: false,
2104
+ Shift: false,
2105
+ Symbol: false,
2106
+ SymbolLock: false
2107
+ },
2108
+ modifierPhase: {}
2109
+ };
2110
+ }
2111
+
2112
+ // src/pointer/parseKeyDef.ts
2113
+ function parseKeyDef2(pointerMap, keys) {
2114
+ const defs = [];
2115
+ do {
2116
+ const {
2117
+ descriptor,
2118
+ consumedLength,
2119
+ releasePrevious,
2120
+ releaseSelf = true
2121
+ } = readNextDescriptor(keys);
2122
+ const keyDef = pointerMap.find((p) => p.name === descriptor);
2123
+ if (keyDef) {
2124
+ defs.push({ keyDef, releasePrevious, releaseSelf });
2125
+ }
2126
+ keys = keys.slice(consumedLength);
2127
+ } while (keys);
2128
+ return defs;
2129
+ }
2130
+
2131
+ // src/pointer/firePointerEvents.ts
2132
+ function firePointerEvent(config, target, type3, {
2133
+ pointerType,
2134
+ button,
2135
+ coords,
2136
+ pointerId,
2137
+ isPrimary,
2138
+ clickCount
2139
+ }) {
2140
+ const init = __spreadValues({}, coords);
2141
+ if (type3 === "click" || type3.startsWith("pointer")) {
2142
+ init.pointerId = pointerId;
2143
+ init.pointerType = pointerType;
2144
+ }
2145
+ if (["pointerdown", "pointerup"].includes(type3)) {
2146
+ init.isPrimary = isPrimary;
2147
+ }
2148
+ init.button = getMouseButton(button != null ? button : 0);
2149
+ init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
2150
+ var _a;
2151
+ return (_a = p.keyDef.button) != null ? _a : 0;
2152
+ }));
2153
+ if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
2154
+ init.detail = clickCount;
2155
+ }
2156
+ return dispatchUIEvent(config, target, type3, init);
2157
+ }
2158
+
2159
+ // src/pointer/resolveSelectionTarget.ts
2160
+ function resolveSelectionTarget({
2161
+ target,
2162
+ node,
2163
+ offset
2164
+ }) {
2165
+ if (isElementType(target, ["input", "textarea"])) {
2166
+ return {
2167
+ node: target,
2168
+ offset: offset != null ? offset : getUIValue(target).length
2169
+ };
2170
+ } else if (node) {
2171
+ return {
2172
+ node,
2173
+ offset: offset != null ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
2174
+ };
2175
+ }
2176
+ return findNodeAtTextOffset(target, offset);
2177
+ }
2178
+ function findNodeAtTextOffset(node, offset, isRoot = true) {
2179
+ let i = offset === void 0 ? node.childNodes.length - 1 : 0;
2180
+ const step = offset === void 0 ? -1 : 1;
2181
+ while (offset === void 0 ? i >= (isRoot ? Math.max(node.childNodes.length - 1, 0) : 0) : i <= node.childNodes.length) {
2182
+ const c = node.childNodes.item(i);
2183
+ const text = String(c.textContent);
2184
+ if (text.length) {
2185
+ if (offset !== void 0 && text.length < offset) {
2186
+ offset -= text.length;
2187
+ } else if (c.nodeType === 1) {
2188
+ return findNodeAtTextOffset(c, offset, false);
2189
+ } else {
2190
+ if (c.nodeType === 3) {
2191
+ return {
2192
+ node: c,
2193
+ offset: offset != null ? offset : c.nodeValue.length
2194
+ };
2195
+ }
2196
+ }
2197
+ }
2198
+ i += step;
2199
+ }
2200
+ return { node, offset: node.childNodes.length };
2201
+ }
2202
+
2203
+ // src/pointer/pointerMove.ts
2204
+ async function pointerMove(config, { pointerName = "mouse", target, coords, node, offset }) {
2205
+ const { pointerState } = config;
2206
+ if (!(pointerName in pointerState.position)) {
2207
+ throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
2208
+ }
2209
+ const {
2210
+ pointerId,
2211
+ pointerType,
2212
+ target: prevTarget,
2213
+ coords: prevCoords,
2214
+ selectionRange
2215
+ } = pointerState.position[pointerName];
2216
+ if (prevTarget && prevTarget !== target) {
2217
+ setLevelRef(config, 2 /* Trigger */);
2218
+ assertPointerEvents(config, prevTarget);
2219
+ fireMove(prevTarget, prevCoords);
2220
+ if (!isDescendantOrSelf(target, prevTarget)) {
2221
+ fireLeave(prevTarget, prevCoords);
2222
+ }
2223
+ }
2224
+ setLevelRef(config, 2 /* Trigger */);
2225
+ assertPointerEvents(config, target);
2226
+ pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
2227
+ target,
2228
+ coords
2229
+ });
2230
+ if (prevTarget !== target) {
2231
+ if (!prevTarget || !isDescendantOrSelf(prevTarget, target)) {
2232
+ fireEnter(target, coords);
2233
+ }
2234
+ }
2235
+ fireMove(target, coords);
2236
+ if (selectionRange) {
2237
+ const selectionFocus = resolveSelectionTarget({ target, node, offset });
2238
+ if ("node" in selectionRange) {
2239
+ if (selectionFocus.node === selectionRange.node) {
2240
+ const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start;
2241
+ const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end;
2242
+ setUISelection(selectionRange.node, { anchorOffset, focusOffset });
2243
+ }
2244
+ } else {
2245
+ const range = selectionRange.cloneRange();
2246
+ const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
2247
+ if (cmp < 0) {
2248
+ range.setStart(selectionFocus.node, selectionFocus.offset);
2249
+ } else if (cmp > 0) {
2250
+ range.setEnd(selectionFocus.node, selectionFocus.offset);
2251
+ }
2252
+ const selection = target.ownerDocument.getSelection();
2253
+ selection.removeAllRanges();
2254
+ selection.addRange(range.cloneRange());
2255
+ }
2256
+ }
2257
+ function fireMove(eventTarget, eventCoords) {
2258
+ fire(eventTarget, "pointermove", eventCoords);
2259
+ if (pointerType === "mouse" && !isDisabled(eventTarget)) {
2260
+ fire(eventTarget, "mousemove", eventCoords);
2261
+ }
2262
+ }
2263
+ function fireLeave(eventTarget, eventCoords) {
2264
+ fire(eventTarget, "pointerout", eventCoords);
2265
+ fire(eventTarget, "pointerleave", eventCoords);
2266
+ if (pointerType === "mouse" && !isDisabled(eventTarget)) {
2267
+ fire(eventTarget, "mouseout", eventCoords);
2268
+ fire(eventTarget, "mouseleave", eventCoords);
2269
+ }
2270
+ }
2271
+ function fireEnter(eventTarget, eventCoords) {
2272
+ fire(eventTarget, "pointerover", eventCoords);
2273
+ fire(eventTarget, "pointerenter", eventCoords);
2274
+ if (pointerType === "mouse" && !isDisabled(eventTarget)) {
2275
+ fire(eventTarget, "mouseover", eventCoords);
2276
+ fire(eventTarget, "mouseenter", eventCoords);
2277
+ }
2278
+ }
2279
+ function fire(eventTarget, type3, eventCoords) {
2280
+ return firePointerEvent(config, eventTarget, type3, {
2281
+ coords: eventCoords,
2282
+ pointerId,
2283
+ pointerType
2284
+ });
2285
+ }
2286
+ }
2287
+
2288
+ // src/pointer/pointerPress.ts
2289
+ async function pointerPress(config, action) {
2290
+ const { keyDef, target, releasePrevious, releaseSelf } = action;
2291
+ const previous = config.pointerState.pressed.find((p) => p.keyDef === keyDef);
2292
+ const pointerName = keyDef.pointerType === "touch" ? keyDef.name : keyDef.pointerType;
2293
+ const targetIsDisabled = isDisabled(target);
2294
+ if (previous) {
2295
+ up(config, pointerName, action, previous, targetIsDisabled);
2296
+ }
2297
+ if (!releasePrevious) {
2298
+ const press = down(config, pointerName, action, targetIsDisabled);
2299
+ if (releaseSelf) {
2300
+ up(config, pointerName, action, press, targetIsDisabled);
2301
+ }
2302
+ }
2303
+ }
2304
+ function getNextPointerId(state) {
2305
+ state.pointerId = state.pointerId + 1;
2306
+ return state.pointerId;
2307
+ }
2308
+ function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
2309
+ var _a, _b, _c;
2310
+ setLevelRef(config, 2 /* Trigger */);
2311
+ assertPointerEvents(config, target);
2312
+ const { pointerState } = config;
2313
+ const { name, pointerType, button } = keyDef;
2314
+ const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
2315
+ pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
2316
+ pointerId,
2317
+ pointerType,
2318
+ target,
2319
+ coords
2320
+ });
2321
+ let isMultiTouch = false;
2322
+ let isPrimary = true;
2323
+ if (pointerType !== "mouse") {
2324
+ for (const obj of pointerState.pressed) {
2325
+ if (obj.keyDef.pointerType === pointerType) {
2326
+ obj.isMultiTouch = true;
2327
+ isMultiTouch = true;
2328
+ isPrimary = false;
2329
+ }
2330
+ }
2331
+ }
2332
+ if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
2333
+ delete pointerState.activeClickCount;
2334
+ }
2335
+ const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
2336
+ pointerState.activeClickCount = [name, clickCount];
2337
+ const pressObj = {
2338
+ keyDef,
2339
+ downTarget: target,
2340
+ pointerId,
2341
+ unpreventedDefault: true,
2342
+ isMultiTouch,
2343
+ isPrimary,
2344
+ clickCount
2345
+ };
2346
+ pointerState.pressed.push(pressObj);
2347
+ if (pointerType !== "mouse") {
2348
+ fire("pointerover");
2349
+ fire("pointerenter");
2350
+ }
2351
+ if (pointerType !== "mouse" || !pointerState.pressed.some((p) => p.keyDef !== keyDef && p.keyDef.pointerType === pointerType)) {
2352
+ fire("pointerdown");
2353
+ }
2354
+ if (pointerType === "mouse") {
2355
+ if (!targetIsDisabled) {
2356
+ pressObj.unpreventedDefault = fire("mousedown");
2357
+ }
2358
+ if (pressObj.unpreventedDefault) {
2359
+ mousedownDefaultBehavior({
2360
+ target,
2361
+ targetIsDisabled,
2362
+ clickCount,
2363
+ position: pointerState.position[pointerName],
2364
+ node,
2365
+ offset
2366
+ });
2367
+ }
2368
+ if (button === "secondary") {
2369
+ fire("contextmenu");
2370
+ }
2371
+ }
2372
+ return pressObj;
2373
+ function fire(type3) {
2374
+ return firePointerEvent(config, target, type3, {
2375
+ button,
2376
+ clickCount,
2377
+ coords,
2378
+ isPrimary,
2379
+ pointerId,
2380
+ pointerType
2381
+ });
2382
+ }
2383
+ }
2384
+ function up(config, pointerName, {
2385
+ keyDef: { pointerType, button },
2386
+ target,
2387
+ coords,
2388
+ node,
2389
+ offset
2390
+ }, pressed, targetIsDisabled) {
2391
+ setLevelRef(config, 2 /* Trigger */);
2392
+ assertPointerEvents(config, target);
2393
+ const { pointerState } = config;
2394
+ pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
2395
+ const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
2396
+ let { unpreventedDefault } = pressed;
2397
+ pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
2398
+ target,
2399
+ coords
2400
+ });
2401
+ if (pointerType !== "mouse" || !pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).length) {
2402
+ fire("pointerup");
2403
+ }
2404
+ if (pointerType !== "mouse") {
2405
+ fire("pointerout");
2406
+ fire("pointerleave");
2407
+ }
2408
+ if (pointerType !== "mouse" && !isMultiTouch) {
2409
+ if (!targetIsDisabled) {
2410
+ if (clickCount === 1) {
2411
+ fire("mouseover");
2412
+ fire("mouseenter");
2413
+ }
2414
+ fire("mousemove");
2415
+ unpreventedDefault = fire("mousedown") && unpreventedDefault;
2416
+ }
2417
+ if (unpreventedDefault) {
2418
+ mousedownDefaultBehavior({
2419
+ target,
2420
+ targetIsDisabled,
2421
+ clickCount,
2422
+ position: pointerState.position[pointerName],
2423
+ node,
2424
+ offset
2425
+ });
2426
+ }
2427
+ }
2428
+ delete pointerState.position[pointerName].selectionRange;
2429
+ if (!targetIsDisabled) {
2430
+ if (pointerType === "mouse" || !isMultiTouch) {
2431
+ unpreventedDefault = fire("mouseup") && unpreventedDefault;
2432
+ const canClick = pointerType !== "mouse" || button === "primary";
2433
+ if (canClick && target === pressed.downTarget) {
2434
+ fire("click");
2435
+ if (clickCount === 2) {
2436
+ fire("dblclick");
2437
+ }
2438
+ }
2439
+ }
2440
+ }
2441
+ function fire(type3) {
2442
+ return firePointerEvent(config, target, type3, {
2443
+ button,
2444
+ clickCount,
2445
+ coords,
2446
+ isPrimary,
2447
+ pointerId,
2448
+ pointerType
2449
+ });
2450
+ }
2451
+ }
2452
+ function mousedownDefaultBehavior({
2453
+ position,
2454
+ target,
2455
+ targetIsDisabled,
2456
+ clickCount,
2457
+ node,
2458
+ offset
2459
+ }) {
2460
+ focus(target);
2461
+ if (!targetIsDisabled) {
2462
+ const hasValue = isElementType(target, ["input", "textarea"]);
2463
+ const text = String(hasValue ? getUIValue(target) : target.textContent);
2464
+ const [start, end] = node ? [offset, offset] : getTextRange(text, offset, clickCount);
2465
+ if (hasValue) {
2466
+ setUISelection(target, {
2467
+ anchorOffset: start != null ? start : text.length,
2468
+ focusOffset: end != null ? end : text.length
2469
+ });
2470
+ position.selectionRange = {
2471
+ node: target,
2472
+ start: start != null ? start : 0,
2473
+ end: end != null ? end : text.length
2474
+ };
2475
+ } else {
2476
+ const { node: startNode, offset: startOffset } = resolveSelectionTarget({
2477
+ target,
2478
+ node,
2479
+ offset: start
2480
+ });
2481
+ const { node: endNode, offset: endOffset } = resolveSelectionTarget({
2482
+ target,
2483
+ node,
2484
+ offset: end
2485
+ });
2486
+ const range = new Range();
2487
+ range.setStart(startNode, startOffset);
2488
+ range.setEnd(endNode, endOffset);
2489
+ position.selectionRange = range;
2490
+ const selection = target.ownerDocument.getSelection();
2491
+ selection.removeAllRanges();
2492
+ selection.addRange(range.cloneRange());
2493
+ }
2494
+ }
2495
+ }
2496
+ function getTextRange(text, pos, clickCount) {
2497
+ if (clickCount % 3 === 1 || text.length === 0) {
2498
+ return [pos, pos];
2499
+ }
2500
+ const textPos = pos != null ? pos : text.length;
2501
+ if (clickCount % 3 === 2) {
2502
+ return [
2503
+ textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
2504
+ pos === void 0 ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
2505
+ ];
2506
+ }
2507
+ return [
2508
+ textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
2509
+ pos === void 0 ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
2510
+ ];
2511
+ }
2512
+
2513
+ // src/pointer/pointerAction.ts
2514
+ async function pointerAction(config, actions) {
2515
+ var _a, _b;
2516
+ for (let i = 0; i < actions.length; i++) {
2517
+ const action = actions[i];
2518
+ const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
2519
+ const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
2520
+ const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
2521
+ await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
2522
+ if (typeof config.delay === "number") {
2523
+ if (i < actions.length - 1) {
2524
+ await wait(config.delay);
2525
+ }
2526
+ }
2527
+ }
2528
+ delete config.pointerState.activeClickCount;
2529
+ }
2530
+ function getPrevTarget(pointerName, state) {
2531
+ if (!(pointerName in state.position) || !state.position[pointerName].target) {
2532
+ throw new Error("This pointer has no previous position. Provide a target property!");
2533
+ }
2534
+ return state.position[pointerName].target;
2535
+ }
2536
+
2537
+ // src/pointer/index.ts
2538
+ async function pointer(input) {
2539
+ const { pointerMap } = this[Config];
2540
+ const actions = [];
2541
+ (Array.isArray(input) ? input : [input]).forEach((actionInput) => {
2542
+ if (typeof actionInput === "string") {
2543
+ actions.push(...parseKeyDef2(pointerMap, actionInput));
2544
+ } else if ("keys" in actionInput) {
2545
+ actions.push(...parseKeyDef2(pointerMap, actionInput.keys).map((i) => __spreadValues(__spreadValues({}, actionInput), i)));
2546
+ } else {
2547
+ actions.push(actionInput);
2548
+ }
2549
+ });
2550
+ return pointerAction(this[Config], actions).then(() => void 0);
2551
+ }
2552
+ function createPointerState(document2) {
2553
+ return {
2554
+ pointerId: 1,
2555
+ position: {
2556
+ mouse: {
2557
+ pointerType: "mouse",
2558
+ pointerId: 1,
2559
+ target: document2.body,
2560
+ coords: {
2561
+ clientX: 0,
2562
+ clientY: 0,
2563
+ offsetX: 0,
2564
+ offsetY: 0,
2565
+ pageX: 0,
2566
+ pageY: 0,
2567
+ x: 0,
2568
+ y: 0
2569
+ }
2570
+ }
2571
+ },
2572
+ pressed: []
2573
+ };
2574
+ }
2575
+
2576
+ // src/setup/config.ts
2577
+ var Config = Symbol("Config");
2578
+
2579
+ // src/setup/api.ts
2580
+ var api_exports = {};
2581
+ __export(api_exports, {
2582
+ clear: () => clear,
2583
+ click: () => click,
2584
+ copy: () => copy,
2585
+ cut: () => cut,
2586
+ dblClick: () => dblClick,
2587
+ deselectOptions: () => deselectOptions,
2588
+ hover: () => hover,
2589
+ keyboard: () => keyboard,
2590
+ paste: () => paste,
2591
+ pointer: () => pointer,
2592
+ selectOptions: () => selectOptions,
2593
+ tab: () => tab,
2594
+ tripleClick: () => tripleClick,
2595
+ type: () => type,
2596
+ unhover: () => unhover,
2597
+ upload: () => upload
2598
+ });
2599
+
2600
+ // src/convenience/click.ts
2601
+ async function click(element) {
2602
+ const pointerIn = [];
2603
+ if (!this[Config].skipHover) {
2604
+ pointerIn.push({ target: element });
2605
+ }
2606
+ pointerIn.push({ keys: "[MouseLeft]", target: element });
2607
+ return this.pointer(pointerIn);
2608
+ }
2609
+ async function dblClick(element) {
2610
+ return this.pointer([{ target: element }, "[MouseLeft][MouseLeft]"]);
2611
+ }
2612
+ async function tripleClick(element) {
2613
+ return this.pointer([{ target: element }, "[MouseLeft][MouseLeft][MouseLeft]"]);
2614
+ }
2615
+
2616
+ // src/convenience/hover.ts
2617
+ async function hover(element) {
2618
+ return this.pointer({ target: element });
2619
+ }
2620
+ async function unhover(element) {
2621
+ return this.pointer({ target: element.ownerDocument.body });
2622
+ }
2623
+
2624
+ // src/convenience/tab.ts
2625
+ async function tab({
2626
+ shift
2627
+ } = {}) {
2628
+ return this.keyboard(shift === true ? "{Shift>}{Tab}{/Shift}" : shift === false ? "[/ShiftLeft][/ShiftRight]{Tab}" : "{Tab}");
2629
+ }
2630
+
2631
+ // src/clipboard/copy.ts
2632
+ async function copy() {
2633
+ var _a;
2634
+ const doc = this[Config].document;
2635
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2636
+ const clipboardData = copySelection(target);
2637
+ if (clipboardData.items.length === 0) {
2638
+ return;
2639
+ }
2640
+ this.dispatchUIEvent(target, "copy", {
2641
+ clipboardData
2642
+ });
2643
+ if (this[Config].writeToClipboard) {
2644
+ await writeDataTransferToClipboard(doc, clipboardData);
2645
+ }
2646
+ return clipboardData;
2647
+ }
2648
+
2649
+ // src/clipboard/cut.ts
2650
+ async function cut() {
2651
+ var _a, _b;
2652
+ const doc = this[Config].document;
2653
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2654
+ const clipboardData = copySelection(target);
2655
+ if (clipboardData.items.length === 0) {
2656
+ return;
2657
+ }
2658
+ this.dispatchUIEvent(target, "cut", {
2659
+ clipboardData
2660
+ });
2661
+ if (isEditable(target)) {
2662
+ (_b = prepareInput(this[Config], "", target, "deleteByCut")) == null ? void 0 : _b.commit();
2663
+ }
2664
+ if (this[Config].writeToClipboard) {
2665
+ await writeDataTransferToClipboard(doc, clipboardData);
2666
+ }
2667
+ return clipboardData;
2668
+ }
2669
+
2670
+ // src/clipboard/paste.ts
2671
+ async function paste(clipboardData) {
2672
+ var _a, _b, _c;
2673
+ const doc = this[Config].document;
2674
+ const target = (_a = doc.activeElement) != null ? _a : doc.body;
2675
+ const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
2676
+ throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
2677
+ });
2678
+ this.dispatchUIEvent(target, "paste", {
2679
+ clipboardData: dataTransfer
2680
+ });
2681
+ if (isEditable(target)) {
2682
+ const textData = dataTransfer.getData("text").substr(0, getSpaceUntilMaxLength(target));
2683
+ if (textData) {
2684
+ (_c = prepareInput(this[Config], textData, target, "insertFromPaste")) == null ? void 0 : _c.commit();
2685
+ }
2686
+ }
2687
+ }
2688
+ function getClipboardDataFromString(text) {
2689
+ const dt = createDataTransfer();
2690
+ dt.setData("text", text);
2691
+ return dt;
2692
+ }
2693
+
2694
+ // src/utility/clear.ts
2695
+ async function clear(element) {
2696
+ var _a;
2697
+ if (!isEditable(element) || isDisabled(element)) {
2698
+ throw new Error("clear()` is only supported on editable elements.");
2699
+ }
2700
+ focus(element);
2701
+ if (element.ownerDocument.activeElement !== element) {
2702
+ throw new Error("The element to be cleared could not be focused.");
2703
+ }
2704
+ selectAll(element);
2705
+ if (!isAllSelected(element)) {
2706
+ throw new Error("The element content to be cleared could not be selected.");
2707
+ }
2708
+ (_a = prepareInput(this[Config], "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
2709
+ }
2710
+
2711
+ // src/utility/selectOptions.ts
2712
+ var import_dom4 = require("@testing-library/dom");
2713
+ async function selectOptions(select, values) {
2714
+ return selectOptionsBase.call(this, true, select, values);
2715
+ }
2716
+ async function deselectOptions(select, values) {
2717
+ return selectOptionsBase.call(this, false, select, values);
2718
+ }
2719
+ async function selectOptionsBase(newValue, select, values) {
2720
+ if (!newValue && !select.multiple) {
2721
+ throw (0, import_dom4.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
2722
+ }
2723
+ const valArray = Array.isArray(values) ? values : [values];
2724
+ const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
2725
+ const selectedOptions = valArray.map((val) => {
2726
+ if (typeof val !== "string" && allOptions.includes(val)) {
2727
+ return val;
2728
+ } else {
2729
+ const matchingOption = allOptions.find((o) => o.value === val || o.innerHTML === val);
2730
+ if (matchingOption) {
2731
+ return matchingOption;
2732
+ } else {
2733
+ throw (0, import_dom4.getConfig)().getElementError(`Value "${String(val)}" not found in options`, select);
2734
+ }
2735
+ }
2736
+ }).filter((option) => !isDisabled(option));
2737
+ if (isDisabled(select) || !selectedOptions.length)
2738
+ return;
2739
+ const selectOption = (option) => {
2740
+ option.selected = newValue;
2741
+ this.dispatchUIEvent(select, "input", {
2742
+ bubbles: true,
2743
+ cancelable: false,
2744
+ composed: true
2745
+ });
2746
+ this.dispatchUIEvent(select, "change");
2747
+ };
2748
+ if (isElementType(select, "select")) {
2749
+ if (select.multiple) {
2750
+ for (const option of selectedOptions) {
2751
+ const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
2752
+ if (withPointerEvents) {
2753
+ this.dispatchUIEvent(option, "pointerover");
2754
+ this.dispatchUIEvent(select, "pointerenter");
2755
+ this.dispatchUIEvent(option, "mouseover");
2756
+ this.dispatchUIEvent(select, "mouseenter");
2757
+ this.dispatchUIEvent(option, "pointermove");
2758
+ this.dispatchUIEvent(option, "mousemove");
2759
+ this.dispatchUIEvent(option, "pointerdown");
2760
+ this.dispatchUIEvent(option, "mousedown");
2761
+ }
2762
+ focus(select);
2763
+ if (withPointerEvents) {
2764
+ this.dispatchUIEvent(option, "pointerup");
2765
+ this.dispatchUIEvent(option, "mouseup");
2766
+ }
2767
+ selectOption(option);
2768
+ if (withPointerEvents) {
2769
+ this.dispatchUIEvent(option, "click");
2770
+ }
2771
+ }
2772
+ } else if (selectedOptions.length === 1) {
2773
+ const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
2774
+ if (withPointerEvents) {
2775
+ await this.click(select);
2776
+ } else {
2777
+ focus(select);
2778
+ }
2779
+ selectOption(selectedOptions[0]);
2780
+ if (withPointerEvents) {
2781
+ this.dispatchUIEvent(select, "pointerover");
2782
+ this.dispatchUIEvent(select, "pointerenter");
2783
+ this.dispatchUIEvent(select, "mouseover");
2784
+ this.dispatchUIEvent(select, "mouseenter");
2785
+ this.dispatchUIEvent(select, "pointerup");
2786
+ this.dispatchUIEvent(select, "mouseup");
2787
+ this.dispatchUIEvent(select, "click");
2788
+ }
2789
+ } else {
2790
+ throw (0, import_dom4.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
2791
+ }
2792
+ } else if (select.getAttribute("role") === "listbox") {
2793
+ for (const option of selectedOptions) {
2794
+ await this.click(option);
2795
+ await this.unhover(option);
2796
+ }
2797
+ } else {
2798
+ throw (0, import_dom4.getConfig)().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
2799
+ }
2800
+ }
2801
+
2802
+ // src/utility/type.ts
2803
+ async function type(element, text, {
2804
+ skipClick = this[Config].skipClick,
2805
+ skipAutoClose = this[Config].skipAutoClose,
2806
+ initialSelectionStart,
2807
+ initialSelectionEnd
2808
+ } = {}) {
2809
+ if (element.disabled)
2810
+ return;
2811
+ if (!skipClick) {
2812
+ await this.click(element);
2813
+ }
2814
+ if (initialSelectionStart !== void 0) {
2815
+ setSelectionRange(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
2816
+ }
2817
+ await this.keyboard(text);
2818
+ if (!skipAutoClose) {
2819
+ await releaseAllKeys(this[Config]);
2820
+ }
2821
+ }
2822
+
2823
+ // src/utility/upload.ts
2824
+ async function upload(element, fileOrFiles) {
2825
+ const input = isElementType(element, "label") ? element.control : element;
2826
+ if (!input || !isElementType(input, "input", { type: "file" })) {
2827
+ throw new TypeError(`The ${input === element ? "given" : "associated"} ${input == null ? void 0 : input.tagName} element does not accept file uploads`);
2828
+ }
2829
+ if (isDisabled(element))
2830
+ return;
2831
+ const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? void 0 : 1);
2832
+ const fileDialog = () => {
2833
+ var _a;
2834
+ if (files.length === ((_a = input.files) == null ? void 0 : _a.length) && files.every((f, i) => {
2835
+ var _a2;
2836
+ return f === ((_a2 = input.files) == null ? void 0 : _a2.item(i));
2837
+ })) {
2838
+ return;
2839
+ }
2840
+ setFiles(input, createFileList(files));
2841
+ this.dispatchUIEvent(input, "input");
2842
+ this.dispatchUIEvent(input, "change");
2843
+ };
2844
+ input.addEventListener("fileDialog", fileDialog);
2845
+ await this.click(element);
2846
+ input.removeEventListener("fileDialog", fileDialog);
2847
+ }
2848
+ function isAcceptableFile(file, accept) {
2849
+ if (!accept) {
2850
+ return true;
2851
+ }
2852
+ const wildcards = ["audio/*", "image/*", "video/*"];
2853
+ return accept.split(",").some((acceptToken) => {
2854
+ if (acceptToken.startsWith(".")) {
2855
+ return file.name.endsWith(acceptToken);
2856
+ } else if (wildcards.includes(acceptToken)) {
2857
+ return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1));
2858
+ }
2859
+ return file.type === acceptToken;
2860
+ });
2861
+ }
2862
+
2863
+ // src/setup/wrapAsync.ts
2864
+ var import_dom5 = require("@testing-library/dom");
2865
+ function wrapAsync(implementation) {
2866
+ return (0, import_dom5.getConfig)().asyncWrapper(implementation);
2867
+ }
2868
+
2869
+ // src/setup/setup.ts
2870
+ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
2871
+ const document2 = getDocument(options, node);
2872
+ const {
2873
+ keyboardState = createKeyboardState(),
2874
+ pointerState = createPointerState(document2)
2875
+ } = options;
2876
+ return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
2877
+ document: document2,
2878
+ keyboardState,
2879
+ pointerState
2880
+ });
2881
+ }
2882
+ function setupMain(options = {}) {
2883
+ var _a;
2884
+ const config = createConfig(options);
2885
+ prepareDocument(config.document);
2886
+ const view = (_a = config.document.defaultView) != null ? _a : window;
2887
+ attachClipboardStubToView(view);
2888
+ return doSetup(config);
2889
+ }
2890
+ function setupDirect(options = {}, node) {
2891
+ const config = createConfig(options, defaultOptionsDirect, node);
2892
+ prepareDocument(config.document);
2893
+ return {
2894
+ config,
2895
+ api: doSetup(config)
2896
+ };
2897
+ }
2898
+ function setupSub(options) {
2899
+ return doSetup(__spreadValues(__spreadValues({}, this[Config]), options));
2900
+ }
2901
+ function wrapAndBindImpl(instance, impl) {
2902
+ function method(...args) {
2903
+ setLevelRef(instance[Config], 1 /* Call */);
2904
+ return wrapAsync(() => impl.apply(instance, args));
2905
+ }
2906
+ Object.defineProperty(method, "name", { get: () => impl.name });
2907
+ return method;
2908
+ }
2909
+ function doSetup(config) {
2910
+ const instance = __spreadValues({
2911
+ [Config]: config,
2912
+ dispatchUIEvent: bindDispatchUIEvent(config)
2913
+ }, api_exports);
2914
+ return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
2915
+ name,
2916
+ wrapAndBindImpl(instance, api)
2917
+ ]))), {
2918
+ setup: setupSub.bind(instance)
2919
+ });
2920
+ }
2921
+ function getDocument(options, node) {
2922
+ var _a, _b;
2923
+ return (_b = (_a = options.document) != null ? _a : node && getDocumentFromNode(node)) != null ? _b : document;
2924
+ }
2925
+
2926
+ // src/setup/directApi.ts
2927
+ var directApi_exports = {};
2928
+ __export(directApi_exports, {
2929
+ clear: () => clear2,
2930
+ click: () => click2,
2931
+ copy: () => copy2,
2932
+ cut: () => cut2,
2933
+ dblClick: () => dblClick2,
2934
+ deselectOptions: () => deselectOptions2,
2935
+ hover: () => hover2,
2936
+ keyboard: () => keyboard2,
2937
+ paste: () => paste2,
2938
+ pointer: () => pointer2,
2939
+ selectOptions: () => selectOptions2,
2940
+ tab: () => tab2,
2941
+ tripleClick: () => tripleClick2,
2942
+ type: () => type2,
2943
+ unhover: () => unhover2,
2944
+ upload: () => upload2
2945
+ });
2946
+ function clear2(element) {
2947
+ return setupDirect().api.clear(element);
2948
+ }
2949
+ function click2(element, options = {}) {
2950
+ return setupDirect(options, element).api.click(element);
2951
+ }
2952
+ function copy2(options = {}) {
2953
+ return setupDirect(options).api.copy();
2954
+ }
2955
+ function cut2(options = {}) {
2956
+ return setupDirect(options).api.cut();
2957
+ }
2958
+ function dblClick2(element, options = {}) {
2959
+ return setupDirect(options).api.dblClick(element);
2960
+ }
2961
+ function deselectOptions2(select, values, options = {}) {
2962
+ return setupDirect(options).api.deselectOptions(select, values);
2963
+ }
2964
+ function hover2(element, options = {}) {
2965
+ return setupDirect(options).api.hover(element);
2966
+ }
2967
+ async function keyboard2(text, options = {}) {
2968
+ const { config, api } = setupDirect(options);
2969
+ return api.keyboard(text).then(() => config.keyboardState);
2970
+ }
2971
+ async function pointer2(input, options = {}) {
2972
+ const { config, api } = setupDirect(options);
2973
+ return api.pointer(input).then(() => config.pointerState);
2974
+ }
2975
+ function paste2(clipboardData, options) {
2976
+ return setupDirect(options).api.paste(clipboardData);
2977
+ }
2978
+ function selectOptions2(select, values, options = {}) {
2979
+ return setupDirect(options).api.selectOptions(select, values);
2980
+ }
2981
+ function tripleClick2(element, options = {}) {
2982
+ return setupDirect(options).api.tripleClick(element);
2983
+ }
2984
+ function type2(element, text, options = {}) {
2985
+ return setupDirect(options, element).api.type(element, text, options);
2986
+ }
2987
+ function unhover2(element, options = {}) {
2988
+ const { config, api } = setupDirect(options);
2989
+ config.pointerState.position.mouse.target = element;
2990
+ return api.unhover(element);
2991
+ }
2992
+ function upload2(element, fileOrFiles, options = {}) {
2993
+ return setupDirect(options).api.upload(element, fileOrFiles);
2994
+ }
2995
+ function tab2(options = {}) {
2996
+ return setupDirect().api.tab(options);
2997
+ }
2998
+
2999
+ // src/setup/index.ts
3000
+ var userEvent = __spreadProps(__spreadValues({}, directApi_exports), {
3001
+ setup: setupMain
3002
+ });
3003
+ module.exports = __toCommonJS(src_exports);