@ariakit/test 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/cjs/__chunks/473V5JUA.cjs +19 -0
  3. package/cjs/__chunks/645PZZGM.cjs +13 -0
  4. package/cjs/__chunks/6PJ6QG4X.cjs +204 -0
  5. package/cjs/__chunks/6WHWNYHF.cjs +56 -0
  6. package/cjs/__chunks/CR7E273F.cjs +70 -0
  7. package/cjs/__chunks/{2V5PIRJZ.cjs → CVZQHCPZ.cjs} +67 -67
  8. package/cjs/__chunks/HNXGMK5P.cjs +35 -0
  9. package/cjs/__chunks/J6ZZZ7OL.cjs +12 -0
  10. package/cjs/__chunks/{LUIPCXQX.cjs → MWZXO7MI.cjs} +45 -42
  11. package/cjs/__chunks/NUOZZLPY.cjs +29 -0
  12. package/cjs/__chunks/OUXW5FPV.cjs +125 -0
  13. package/cjs/__chunks/R25SVNFL.cjs +94 -0
  14. package/cjs/__chunks/R7VOUI26.cjs +32 -0
  15. package/cjs/__chunks/SSTGZXPB.cjs +57 -0
  16. package/cjs/__chunks/YJVLDF2F.cjs +68 -0
  17. package/cjs/__utils.d.ts +6 -3
  18. package/cjs/blur.cjs +4 -6
  19. package/cjs/blur.d.ts +1 -2
  20. package/cjs/click.cjs +10 -12
  21. package/cjs/click.d.ts +1 -2
  22. package/cjs/dispatch.cjs +8 -0
  23. package/cjs/dispatch.d.ts +9 -0
  24. package/cjs/focus.cjs +4 -6
  25. package/cjs/focus.d.ts +1 -2
  26. package/cjs/hover.cjs +5 -7
  27. package/cjs/hover.d.ts +1 -2
  28. package/cjs/index.cjs +17 -75
  29. package/cjs/index.d.ts +2 -5
  30. package/cjs/mouse-down.cjs +6 -8
  31. package/cjs/mouse-down.d.ts +1 -2
  32. package/cjs/mouse-up.cjs +4 -5
  33. package/cjs/mouse-up.d.ts +1 -2
  34. package/cjs/press.cjs +8 -10
  35. package/cjs/press.d.ts +0 -1
  36. package/cjs/query.cjs +9 -0
  37. package/cjs/query.d.ts +3989 -0
  38. package/cjs/react.cjs +89 -0
  39. package/cjs/react.d.ts +7 -0
  40. package/cjs/select.cjs +10 -12
  41. package/cjs/select.d.ts +1 -2
  42. package/cjs/sleep.cjs +3 -4
  43. package/cjs/tap.cjs +11 -13
  44. package/cjs/tap.d.ts +1 -2
  45. package/cjs/tsconfig.build.tsbuildinfo +1 -1
  46. package/cjs/type.cjs +6 -8
  47. package/cjs/type.d.ts +0 -1
  48. package/cjs/wait-for.cjs +3 -2
  49. package/cjs/wait-for.d.ts +2 -1
  50. package/dispatch/package.json +8 -0
  51. package/esm/__chunks/{6PY4HXVO.js → 2YBPSAHP.js} +69 -69
  52. package/esm/__chunks/33MQDYWJ.js +125 -0
  53. package/esm/__chunks/45H4QFE4.js +94 -0
  54. package/esm/__chunks/4NZZR22G.js +35 -0
  55. package/esm/__chunks/7I22ZP6R.js +13 -0
  56. package/esm/__chunks/BKSZ7WES.js +204 -0
  57. package/esm/__chunks/MOHPNQYM.js +70 -0
  58. package/esm/__chunks/PGGOW3IT.js +57 -0
  59. package/esm/__chunks/SKXK6BOG.js +29 -0
  60. package/esm/__chunks/WWAF2MEB.js +12 -0
  61. package/esm/__chunks/{SWUQE4WB.js → X5N4V7NJ.js} +46 -43
  62. package/esm/__chunks/Y4VDXWJ6.js +32 -0
  63. package/esm/__chunks/YXZMMBB6.js +19 -0
  64. package/esm/__chunks/ZJJNX53K.js +68 -0
  65. package/esm/__chunks/ZU6UY6LZ.js +56 -0
  66. package/esm/__utils.d.ts +6 -3
  67. package/esm/blur.d.ts +1 -2
  68. package/esm/blur.js +3 -5
  69. package/esm/click.d.ts +1 -2
  70. package/esm/click.js +9 -11
  71. package/esm/dispatch.d.ts +9 -0
  72. package/esm/dispatch.js +8 -0
  73. package/esm/focus.d.ts +1 -2
  74. package/esm/focus.js +3 -5
  75. package/esm/hover.d.ts +1 -2
  76. package/esm/hover.js +4 -6
  77. package/esm/index.d.ts +2 -5
  78. package/esm/index.js +29 -87
  79. package/esm/mouse-down.d.ts +1 -2
  80. package/esm/mouse-down.js +5 -7
  81. package/esm/mouse-up.d.ts +1 -2
  82. package/esm/mouse-up.js +3 -4
  83. package/esm/press.d.ts +0 -1
  84. package/esm/press.js +7 -9
  85. package/esm/query.d.ts +3989 -0
  86. package/esm/query.js +9 -0
  87. package/esm/react.d.ts +7 -0
  88. package/esm/react.js +89 -0
  89. package/esm/select.d.ts +1 -2
  90. package/esm/select.js +9 -11
  91. package/esm/sleep.js +2 -3
  92. package/esm/tap.d.ts +1 -2
  93. package/esm/tap.js +10 -12
  94. package/esm/tsconfig.build.tsbuildinfo +1 -1
  95. package/esm/type.d.ts +0 -1
  96. package/esm/type.js +5 -7
  97. package/esm/wait-for.d.ts +2 -1
  98. package/esm/wait-for.js +2 -1
  99. package/package.json +21 -24
  100. package/query/package.json +8 -0
  101. package/react/package.json +8 -0
  102. package/act/package.json +0 -8
  103. package/cjs/__chunks/3NIZQX5J.cjs +0 -6
  104. package/cjs/__chunks/3WW644T7.cjs +0 -20
  105. package/cjs/__chunks/5F5PNQCC.cjs +0 -22
  106. package/cjs/__chunks/7BZFO6FC.cjs +0 -12
  107. package/cjs/__chunks/7RUXTAPP.cjs +0 -16
  108. package/cjs/__chunks/B4VP2LEU.cjs +0 -28
  109. package/cjs/__chunks/BHNBCXUN.cjs +0 -33
  110. package/cjs/__chunks/EGF4KWUK.cjs +0 -64
  111. package/cjs/__chunks/HGTTGPFK.cjs +0 -54
  112. package/cjs/__chunks/JY5DGPUE.cjs +0 -14
  113. package/cjs/__chunks/KRQVK4KQ.cjs +0 -38
  114. package/cjs/__chunks/LFNIGEB6.cjs +0 -50
  115. package/cjs/__chunks/MQA5IB4L.cjs +0 -6
  116. package/cjs/__chunks/Q7PN3HIB.cjs +0 -121
  117. package/cjs/__chunks/SYQ5J5KP.cjs +0 -32
  118. package/cjs/__chunks/VIKUJSTX.cjs +0 -83
  119. package/cjs/act.cjs +0 -8
  120. package/cjs/act.d.ts +0 -1
  121. package/cjs/fire-event.cjs +0 -9
  122. package/cjs/fire-event.d.ts +0 -3
  123. package/cjs/polyfills.cjs +0 -3
  124. package/cjs/polyfills.d.ts +0 -1
  125. package/cjs/render.cjs +0 -9
  126. package/cjs/render.d.ts +0 -5
  127. package/cjs/screen.cjs +0 -55
  128. package/cjs/screen.d.ts +0 -26
  129. package/cjs/within.cjs +0 -7
  130. package/cjs/within.d.ts +0 -1
  131. package/esm/__chunks/2OZA4WAZ.js +0 -50
  132. package/esm/__chunks/2RHTJFSK.js +0 -38
  133. package/esm/__chunks/3C72DPE2.js +0 -54
  134. package/esm/__chunks/4A3YKZRA.js +0 -121
  135. package/esm/__chunks/5JPM5LQX.js +0 -6
  136. package/esm/__chunks/5PINJ4MD.js +0 -16
  137. package/esm/__chunks/AEOE57TZ.js +0 -33
  138. package/esm/__chunks/EVYPE6ZJ.js +0 -32
  139. package/esm/__chunks/EX5WPJOU.js +0 -64
  140. package/esm/__chunks/JTFRQL3H.js +0 -83
  141. package/esm/__chunks/LJWZLI6L.js +0 -14
  142. package/esm/__chunks/OQYWQML5.js +0 -12
  143. package/esm/__chunks/OSCTTZUZ.js +0 -28
  144. package/esm/__chunks/QA3ZS6S2.js +0 -6
  145. package/esm/__chunks/R7IYW63J.js +0 -22
  146. package/esm/__chunks/ZEO5Q6UD.js +0 -20
  147. package/esm/act.d.ts +0 -1
  148. package/esm/act.js +0 -8
  149. package/esm/fire-event.d.ts +0 -3
  150. package/esm/fire-event.js +0 -9
  151. package/esm/polyfills.d.ts +0 -1
  152. package/esm/polyfills.js +0 -3
  153. package/esm/render.d.ts +0 -5
  154. package/esm/render.js +0 -9
  155. package/esm/screen.d.ts +0 -26
  156. package/esm/screen.js +0 -55
  157. package/esm/within.d.ts +0 -1
  158. package/esm/within.js +0 -7
  159. package/fire-event/package.json +0 -8
  160. package/polyfills/package.json +0 -8
  161. package/render/package.json +0 -8
  162. package/screen/package.json +0 -8
  163. package/within/package.json +0 -8
  164. /package/cjs/__chunks/{AYRPODWR.cjs → IDMD7IDF.cjs} +0 -0
  165. /package/esm/__chunks/{PNBZ5NXH.js → 36HVAQ4Z.js} +0 -0
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  type
3
- } from "./4A3YKZRA.js";
3
+ } from "./33MQDYWJ.js";
4
4
  import {
5
5
  blur
6
- } from "./AEOE57TZ.js";
6
+ } from "./4NZZR22G.js";
7
7
  import {
8
8
  focus
9
- } from "./OSCTTZUZ.js";
9
+ } from "./Y4VDXWJ6.js";
10
10
  import {
11
- fireEvent
12
- } from "./2RHTJFSK.js";
11
+ dispatch
12
+ } from "./ZU6UY6LZ.js";
13
13
  import {
14
14
  sleep
15
- } from "./5PINJ4MD.js";
15
+ } from "./YXZMMBB6.js";
16
16
  import {
17
- queuedMicrotasks
18
- } from "./ZEO5Q6UD.js";
17
+ wrapAsync
18
+ } from "./MOHPNQYM.js";
19
19
  import {
20
20
  __spreadValues
21
21
  } from "./6XO5G2QR.js";
@@ -35,7 +35,7 @@ var clickableInputTypes = [
35
35
  "reset",
36
36
  "submit"
37
37
  ];
38
- function submitFormByPressingEnterOn(element, options) {
38
+ async function submitFormByPressingEnterOn(element, options) {
39
39
  const { form } = element;
40
40
  if (!form)
41
41
  return;
@@ -47,40 +47,40 @@ function submitFormByPressingEnterOn(element, options) {
47
47
  (el) => (el instanceof HTMLInputElement || el instanceof HTMLButtonElement) && el.type === "submit"
48
48
  );
49
49
  if (validInputs.length === 1 || submitButton) {
50
- fireEvent.submit(form, options);
50
+ await dispatch.submit(form, options);
51
51
  }
52
52
  }
53
53
  function isNumberInput(element) {
54
54
  return element instanceof HTMLInputElement && element.type === "number";
55
55
  }
56
- function incrementNumberInput(element, by = 1) {
56
+ async function incrementNumberInput(element, by = 1) {
57
57
  const value = +element.value + by;
58
58
  const max = element.max ? +element.max : Number.MAX_SAFE_INTEGER;
59
59
  const min = element.min ? +element.min : Number.MIN_SAFE_INTEGER;
60
60
  if (value > max || value < min)
61
61
  return;
62
62
  element.value = value.toString();
63
- fireEvent.input(element);
64
- fireEvent.change(element);
63
+ await dispatch.input(element);
64
+ await dispatch.change(element);
65
65
  }
66
66
  var keyDownMap = {
67
- Tab(_, { shiftKey }) {
67
+ async Tab(_, { shiftKey }) {
68
68
  const nextElement = shiftKey ? getPreviousTabbable() : getNextTabbable();
69
69
  if (nextElement) {
70
- focus(nextElement);
70
+ await focus(nextElement);
71
71
  }
72
72
  },
73
- Enter(element, options) {
73
+ async Enter(element, options) {
74
74
  const nonSubmittableTypes = [...clickableInputTypes, "hidden"];
75
75
  const isClickable = element.tagName === "BUTTON" || element instanceof HTMLInputElement && clickableInputTypes.includes(element.type);
76
76
  const isSubmittable = element instanceof HTMLInputElement && !nonSubmittableTypes.includes(element.type);
77
77
  if (isClickable) {
78
- fireEvent.click(element, options);
78
+ await dispatch.click(element, options);
79
79
  } else if (isSubmittable) {
80
- submitFormByPressingEnterOn(element, options);
80
+ await submitFormByPressingEnterOn(element, options);
81
81
  }
82
82
  },
83
- ArrowLeft(element, { shiftKey }) {
83
+ async ArrowLeft(element, { shiftKey }) {
84
84
  if (isTextField(element)) {
85
85
  const { value, selectionStart, selectionEnd, selectionDirection } = element;
86
86
  const [start, end] = [selectionStart != null ? selectionStart : 0, selectionEnd != null ? selectionEnd : 0];
@@ -94,7 +94,7 @@ var keyDownMap = {
94
94
  );
95
95
  }
96
96
  },
97
- ArrowRight(element, { shiftKey }) {
97
+ async ArrowRight(element, { shiftKey }) {
98
98
  if (isTextField(element)) {
99
99
  const { value, selectionStart, selectionEnd, selectionDirection } = element;
100
100
  const [start, end] = [selectionStart != null ? selectionStart : 0, selectionEnd != null ? selectionEnd : 0];
@@ -108,7 +108,7 @@ var keyDownMap = {
108
108
  );
109
109
  }
110
110
  },
111
- ArrowUp(element, { shiftKey }) {
111
+ async ArrowUp(element, { shiftKey }) {
112
112
  if (isTextField(element)) {
113
113
  if (!shiftKey) {
114
114
  return element.setSelectionRange(0, 0);
@@ -122,10 +122,10 @@ var keyDownMap = {
122
122
  }
123
123
  }
124
124
  } else if (isNumberInput(element)) {
125
- incrementNumberInput(element);
125
+ await incrementNumberInput(element);
126
126
  }
127
127
  },
128
- ArrowDown(element, { shiftKey }) {
128
+ async ArrowDown(element, { shiftKey }) {
129
129
  if (isTextField(element)) {
130
130
  const length = element.value.length;
131
131
  if (!shiftKey) {
@@ -140,65 +140,65 @@ var keyDownMap = {
140
140
  }
141
141
  }
142
142
  } else if (isNumberInput(element)) {
143
- incrementNumberInput(element, -1);
143
+ await incrementNumberInput(element, -1);
144
144
  }
145
145
  }
146
146
  };
147
147
  var keyUpMap = {
148
148
  // Space
149
- " ": (element, options) => {
149
+ " ": async (element, options) => {
150
150
  const spaceableTypes = [...clickableInputTypes, "checkbox", "radio"];
151
151
  const isSpaceable = element.tagName === "BUTTON" || element instanceof HTMLInputElement && spaceableTypes.includes(element.type);
152
152
  if (isSpaceable) {
153
- fireEvent.click(element, options);
153
+ await dispatch.click(element, options);
154
154
  }
155
155
  }
156
156
  };
157
- async function press(key, element, options = {}) {
158
- var _a, _b, _c, _d;
159
- if (element == null) {
160
- element = document.activeElement || document.body;
161
- }
162
- if (!element)
163
- return;
164
- if (!isFocusable(element) && element.tagName !== "BODY")
165
- return;
166
- if (isTextField(element)) {
167
- if (key.length === 1) {
168
- return type(key, element, options);
169
- } else if (key === "Delete") {
170
- return type("\x7F", element, options);
171
- } else if (key === "Backspace") {
172
- return type("\b", element, options);
173
- } else if (key === "Enter" && element.tagName === "TEXTAREA") {
174
- return type("\n", element, options);
157
+ function press(key, element, options = {}) {
158
+ return wrapAsync(async () => {
159
+ var _a, _b, _c, _d;
160
+ if (element == null) {
161
+ element = document.activeElement || document.body;
175
162
  }
176
- }
177
- if (((_a = element.ownerDocument) == null ? void 0 : _a.activeElement) !== element) {
178
- if (element.tagName === "BODY") {
179
- blur();
180
- } else {
181
- focus(element);
163
+ if (!element)
164
+ return;
165
+ if (!isFocusable(element) && element.tagName !== "BODY")
166
+ return;
167
+ if (isTextField(element)) {
168
+ if (key.length === 1) {
169
+ return type(key, element, options);
170
+ } else if (key === "Delete") {
171
+ return type("\x7F", element, options);
172
+ } else if (key === "Backspace") {
173
+ return type("\b", element, options);
174
+ } else if (key === "Enter" && element.tagName === "TEXTAREA") {
175
+ return type("\n", element, options);
176
+ }
182
177
  }
183
- }
184
- await sleep();
185
- let defaultAllowed = fireEvent.keyDown(element, __spreadValues({ key }, options));
186
- await queuedMicrotasks();
187
- if (defaultAllowed && key in keyDownMap && !options.metaKey) {
188
- (_b = keyDownMap[key]) == null ? void 0 : _b.call(keyDownMap, element, options);
189
- }
190
- await sleep();
191
- if (((_c = element.ownerDocument) == null ? void 0 : _c.activeElement) !== element) {
192
- element = element.ownerDocument.activeElement;
193
- }
194
- if (!fireEvent.keyUp(element, __spreadValues({ key }, options))) {
195
- defaultAllowed = false;
196
- }
197
- await queuedMicrotasks();
198
- if (defaultAllowed && key in keyUpMap && !options.metaKey) {
199
- (_d = keyUpMap[key]) == null ? void 0 : _d.call(keyUpMap, element, options);
200
- }
201
- await sleep();
178
+ if (((_a = element.ownerDocument) == null ? void 0 : _a.activeElement) !== element) {
179
+ if (element.tagName === "BODY") {
180
+ await blur();
181
+ } else {
182
+ await focus(element);
183
+ }
184
+ }
185
+ await sleep();
186
+ let defaultAllowed = await dispatch.keyDown(element, __spreadValues({ key }, options));
187
+ if (defaultAllowed && key in keyDownMap && !options.metaKey) {
188
+ await ((_b = keyDownMap[key]) == null ? void 0 : _b.call(keyDownMap, element, options));
189
+ }
190
+ await sleep();
191
+ if (((_c = element.ownerDocument) == null ? void 0 : _c.activeElement) !== element) {
192
+ element = element.ownerDocument.activeElement;
193
+ }
194
+ if (!await dispatch.keyUp(element, __spreadValues({ key }, options))) {
195
+ defaultAllowed = false;
196
+ }
197
+ if (defaultAllowed && key in keyUpMap && !options.metaKey) {
198
+ await ((_d = keyUpMap[key]) == null ? void 0 : _d.call(keyUpMap, element, options));
199
+ }
200
+ await sleep();
201
+ });
202
202
  }
203
203
  function createPress(key, defaultOptions = {}) {
204
204
  return (element, options = {}) => press(key, element, __spreadValues(__spreadValues({}, defaultOptions), options));
@@ -0,0 +1,125 @@
1
+ import {
2
+ focus
3
+ } from "./Y4VDXWJ6.js";
4
+ import {
5
+ dispatch
6
+ } from "./ZU6UY6LZ.js";
7
+ import {
8
+ sleep
9
+ } from "./YXZMMBB6.js";
10
+ import {
11
+ wrapAsync
12
+ } from "./MOHPNQYM.js";
13
+ import {
14
+ __spreadValues
15
+ } from "./6XO5G2QR.js";
16
+
17
+ // src/type.ts
18
+ import { getActiveElement, isTextField } from "@ariakit/core/utils/dom";
19
+ import { isFocusable } from "@ariakit/core/utils/focus";
20
+ function getKeyFromChar(key) {
21
+ if (key === "\x7F")
22
+ return "Delete";
23
+ if (key === "\b")
24
+ return "Backspace";
25
+ if (key === "\n")
26
+ return "Enter";
27
+ if (key === " ")
28
+ return "Tab";
29
+ return key;
30
+ }
31
+ function workAroundEmailInput(element) {
32
+ const input = element;
33
+ if (input.tagName !== "INPUT" || input.type !== "email")
34
+ return () => {
35
+ };
36
+ input.type = "text";
37
+ return () => {
38
+ input.type = "email";
39
+ };
40
+ }
41
+ function type(text, element, options = {}) {
42
+ return wrapAsync(async () => {
43
+ var _a, _b;
44
+ if (element == null) {
45
+ element = document.activeElement;
46
+ }
47
+ if (!element)
48
+ return;
49
+ if (!isFocusable(element))
50
+ return;
51
+ await focus(element);
52
+ element.dirty = true;
53
+ const restoreEmailInput = workAroundEmailInput(element);
54
+ for (const char of text) {
55
+ const key = getKeyFromChar(char);
56
+ let value = "";
57
+ let inputType = options.isComposing ? "insertCompositionText" : "insertText";
58
+ let defaultAllowed = await dispatch.keyDown(element, __spreadValues({ key }, options));
59
+ element = getActiveElement(element) || element;
60
+ if (isTextField(element)) {
61
+ const input = element;
62
+ const [start, end] = [
63
+ (_a = input.selectionStart) != null ? _a : 0,
64
+ (_b = input.selectionEnd) != null ? _b : 0
65
+ ];
66
+ const collapsed = start === end;
67
+ let nextCaretPosition = start;
68
+ if (char === "\x7F") {
69
+ const firstPart = input.value.slice(0, start);
70
+ const secondPart = input.value.slice(collapsed ? end + 1 : end);
71
+ value = `${firstPart}${secondPart}`;
72
+ inputType = "deleteContentForward";
73
+ } else if (char === "\b") {
74
+ nextCaretPosition = collapsed ? Math.max(start - 1, 0) : start;
75
+ const firstPart = input.value.slice(0, nextCaretPosition);
76
+ const lastPart = input.value.slice(end, input.value.length);
77
+ value = `${firstPart}${lastPart}`;
78
+ inputType = "deleteContentBackward";
79
+ } else {
80
+ const firstPartEnd = options.isComposing ? start - 1 : start;
81
+ const firstPart = input.value.slice(0, firstPartEnd);
82
+ const lastPart = input.value.slice(end, input.value.length);
83
+ nextCaretPosition = start + 1;
84
+ value = `${firstPart}${char}${lastPart}`;
85
+ }
86
+ if (defaultAllowed && !input.readOnly) {
87
+ if (inputType === "insertText") {
88
+ defaultAllowed = await dispatch.keyPress(input, __spreadValues({
89
+ key,
90
+ charCode: key.charCodeAt(0)
91
+ }, options));
92
+ }
93
+ if (inputType === "insertCompositionText") {
94
+ defaultAllowed = await dispatch.compositionUpdate(input, __spreadValues({
95
+ data: char,
96
+ target: { value }
97
+ }, options));
98
+ }
99
+ if (defaultAllowed) {
100
+ await dispatch.input(input, __spreadValues({
101
+ data: char,
102
+ target: {
103
+ value,
104
+ selectionStart: nextCaretPosition,
105
+ selectionEnd: nextCaretPosition
106
+ },
107
+ inputType
108
+ }, options));
109
+ if (input.selectionStart !== nextCaretPosition) {
110
+ input.setSelectionRange(nextCaretPosition, nextCaretPosition);
111
+ }
112
+ }
113
+ }
114
+ }
115
+ await sleep();
116
+ await dispatch.keyUp(element, __spreadValues({ key }, options));
117
+ await sleep();
118
+ }
119
+ restoreEmailInput();
120
+ });
121
+ }
122
+
123
+ export {
124
+ type
125
+ };
@@ -0,0 +1,94 @@
1
+ import {
2
+ mouseUp
3
+ } from "./SKXK6BOG.js";
4
+ import {
5
+ mouseDown
6
+ } from "./PGGOW3IT.js";
7
+ import {
8
+ hover
9
+ } from "./ZJJNX53K.js";
10
+ import {
11
+ dispatch
12
+ } from "./ZU6UY6LZ.js";
13
+ import {
14
+ sleep
15
+ } from "./YXZMMBB6.js";
16
+ import {
17
+ wrapAsync
18
+ } from "./MOHPNQYM.js";
19
+ import {
20
+ __spreadValues
21
+ } from "./6XO5G2QR.js";
22
+
23
+ // src/select.ts
24
+ import { isVisible } from "@ariakit/core/utils/dom";
25
+ import { invariant } from "@ariakit/core/utils/misc";
26
+ function select(text, element = document.body, options) {
27
+ return wrapAsync(async () => {
28
+ var _a, _b;
29
+ invariant(element, "Unable to select text on null element");
30
+ if (!isVisible(element))
31
+ return;
32
+ const document2 = element.ownerDocument;
33
+ await hover(element, options);
34
+ await mouseDown(element, options);
35
+ await dispatch(
36
+ element,
37
+ new Event("selectstart", {
38
+ bubbles: true,
39
+ cancelable: true,
40
+ composed: false
41
+ })
42
+ );
43
+ const startIndex = (_b = (_a = element.textContent) == null ? void 0 : _a.indexOf(text)) != null ? _b : -1;
44
+ const selection = document2.getSelection();
45
+ const range = document2.createRange();
46
+ for (let i = 1; i <= text.length; i++) {
47
+ const iterator = document2.createNodeIterator(
48
+ element,
49
+ NodeFilter.SHOW_TEXT
50
+ );
51
+ const textSlice = text.slice(0, i);
52
+ const endIndex = startIndex + textSlice.length;
53
+ let index = startIndex;
54
+ let node = null;
55
+ let charCount = 0;
56
+ let startContainer = null;
57
+ let startOffset = -1;
58
+ let endContainer = null;
59
+ let endOffset = -1;
60
+ while (index >= 0 && index < endIndex && charCount < endIndex && (node = iterator.nextNode())) {
61
+ const textContent = node.textContent;
62
+ if (!textContent)
63
+ continue;
64
+ charCount += textContent.length;
65
+ if (index > charCount)
66
+ continue;
67
+ if (!startContainer) {
68
+ startContainer = node;
69
+ startOffset = index - charCount + textContent.length;
70
+ }
71
+ endContainer = node;
72
+ endOffset = endIndex - charCount + textContent.length;
73
+ index++;
74
+ }
75
+ if (!startContainer || !endContainer)
76
+ continue;
77
+ await hover(element, options);
78
+ range.setStart(startContainer, startOffset);
79
+ range.setEnd(endContainer, endOffset);
80
+ selection == null ? void 0 : selection.removeAllRanges();
81
+ selection == null ? void 0 : selection.addRange(range);
82
+ }
83
+ await sleep();
84
+ await mouseUp(element, options);
85
+ await dispatch.click(element, __spreadValues({ detail: 1 }, options));
86
+ selection == null ? void 0 : selection.removeAllRanges();
87
+ selection == null ? void 0 : selection.addRange(range);
88
+ await sleep();
89
+ });
90
+ }
91
+
92
+ export {
93
+ select
94
+ };
@@ -0,0 +1,35 @@
1
+ import {
2
+ dispatch
3
+ } from "./ZU6UY6LZ.js";
4
+ import {
5
+ flushMicrotasks,
6
+ wrapAsync
7
+ } from "./MOHPNQYM.js";
8
+
9
+ // src/blur.ts
10
+ import { getActiveElement } from "@ariakit/core/utils/dom";
11
+ function blur(element) {
12
+ return wrapAsync(async () => {
13
+ if (element == null) {
14
+ element = document.activeElement;
15
+ }
16
+ if (!element)
17
+ return;
18
+ if (element.tagName === "BODY")
19
+ return;
20
+ if (getActiveElement(element) !== element)
21
+ return;
22
+ if (element.dirty) {
23
+ await dispatch.change(element);
24
+ element.dirty = false;
25
+ }
26
+ if (element instanceof HTMLElement || element instanceof SVGElement) {
27
+ element.blur();
28
+ await flushMicrotasks();
29
+ }
30
+ });
31
+ }
32
+
33
+ export {
34
+ blur
35
+ };
@@ -0,0 +1,13 @@
1
+ import {
2
+ wrapAsync
3
+ } from "./MOHPNQYM.js";
4
+
5
+ // src/wait-for.ts
6
+ import * as DOMTestingLibrary from "@testing-library/dom";
7
+ function waitFor2(callback, options) {
8
+ return wrapAsync(() => DOMTestingLibrary.waitFor(callback, options));
9
+ }
10
+
11
+ export {
12
+ waitFor2 as waitFor
13
+ };