@testing-library/user-event 14.2.6 → 14.4.1

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