@wordpress/dom 5.0.0 → 5.1.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 (210) hide show
  1. package/README.md +1 -1
  2. package/build/data-transfer.cjs +20 -38
  3. package/build/data-transfer.cjs.map +1 -7
  4. package/build/dom/caret-range-from-point.cjs +31 -38
  5. package/build/dom/caret-range-from-point.cjs.map +1 -7
  6. package/build/dom/clean-node-list.cjs +87 -132
  7. package/build/dom/clean-node-list.cjs.map +1 -7
  8. package/build/dom/compute-caret-rect.cjs +35 -35
  9. package/build/dom/compute-caret-rect.cjs.map +1 -7
  10. package/build/dom/document-has-selection.cjs +35 -30
  11. package/build/dom/document-has-selection.cjs.map +1 -7
  12. package/build/dom/document-has-text-selection.cjs +24 -30
  13. package/build/dom/document-has-text-selection.cjs.map +1 -7
  14. package/build/dom/document-has-uncollapsed-selection.cjs +34 -29
  15. package/build/dom/document-has-uncollapsed-selection.cjs.map +1 -7
  16. package/build/dom/get-computed-style.cjs +14 -30
  17. package/build/dom/get-computed-style.cjs.map +1 -7
  18. package/build/dom/get-offset-parent.cjs +40 -39
  19. package/build/dom/get-offset-parent.cjs.map +1 -7
  20. package/build/dom/get-range-height.cjs +18 -31
  21. package/build/dom/get-range-height.cjs.map +1 -7
  22. package/build/dom/get-rectangle-from-range.cjs +82 -128
  23. package/build/dom/get-rectangle-from-range.cjs.map +1 -7
  24. package/build/dom/get-scroll-container.cjs +46 -50
  25. package/build/dom/get-scroll-container.cjs.map +1 -7
  26. package/build/dom/hidden-caret-range-from-point.cjs +48 -42
  27. package/build/dom/hidden-caret-range-from-point.cjs.map +1 -7
  28. package/build/dom/index.cjs +233 -110
  29. package/build/dom/input-field-has-uncollapsed-selection.cjs +48 -43
  30. package/build/dom/input-field-has-uncollapsed-selection.cjs.map +1 -7
  31. package/build/dom/insert-after.cjs +17 -27
  32. package/build/dom/insert-after.cjs.map +1 -7
  33. package/build/dom/is-edge.cjs +82 -97
  34. package/build/dom/is-edge.cjs.map +1 -7
  35. package/build/dom/is-element.cjs +12 -25
  36. package/build/dom/is-element.cjs.map +1 -7
  37. package/build/dom/is-empty.cjs +23 -37
  38. package/build/dom/is-empty.cjs.map +1 -7
  39. package/build/dom/is-entirely-selected.cjs +70 -67
  40. package/build/dom/is-entirely-selected.cjs.map +1 -7
  41. package/build/dom/is-form-element.cjs +33 -33
  42. package/build/dom/is-form-element.cjs.map +1 -7
  43. package/build/dom/is-horizontal-edge.cjs +31 -28
  44. package/build/dom/is-horizontal-edge.cjs.map +1 -7
  45. package/build/dom/is-html-input-element.cjs +12 -25
  46. package/build/dom/is-html-input-element.cjs.map +1 -7
  47. package/build/dom/is-input-or-text-area.cjs +12 -25
  48. package/build/dom/is-input-or-text-area.cjs.map +1 -7
  49. package/build/dom/is-number-input.cjs +36 -33
  50. package/build/dom/is-number-input.cjs.map +1 -7
  51. package/build/dom/is-rtl.cjs +30 -28
  52. package/build/dom/is-rtl.cjs.map +1 -7
  53. package/build/dom/is-selection-forward.cjs +26 -39
  54. package/build/dom/is-selection-forward.cjs.map +1 -7
  55. package/build/dom/is-text-field.cjs +45 -42
  56. package/build/dom/is-text-field.cjs.map +1 -7
  57. package/build/dom/is-vertical-edge.cjs +31 -28
  58. package/build/dom/is-vertical-edge.cjs.map +1 -7
  59. package/build/dom/place-caret-at-edge.cjs +75 -78
  60. package/build/dom/place-caret-at-edge.cjs.map +1 -7
  61. package/build/dom/place-caret-at-horizontal-edge.cjs +29 -28
  62. package/build/dom/place-caret-at-horizontal-edge.cjs.map +1 -7
  63. package/build/dom/place-caret-at-vertical-edge.cjs +30 -28
  64. package/build/dom/place-caret-at-vertical-edge.cjs.map +1 -7
  65. package/build/dom/remove-invalid-html.cjs +35 -31
  66. package/build/dom/remove-invalid-html.cjs.map +1 -7
  67. package/build/dom/remove.cjs +15 -27
  68. package/build/dom/remove.cjs.map +1 -7
  69. package/build/dom/replace-tag.cjs +21 -32
  70. package/build/dom/replace-tag.cjs.map +1 -7
  71. package/build/dom/replace.cjs +34 -32
  72. package/build/dom/replace.cjs.map +1 -7
  73. package/build/dom/safe-html.cjs +45 -46
  74. package/build/dom/safe-html.cjs.map +1 -7
  75. package/build/dom/scroll-if-no-range.cjs +24 -37
  76. package/build/dom/scroll-if-no-range.cjs.map +1 -7
  77. package/build/dom/strip-html.cjs +33 -31
  78. package/build/dom/strip-html.cjs.map +1 -7
  79. package/build/dom/types.cjs +4 -18
  80. package/build/dom/unwrap.cjs +17 -31
  81. package/build/dom/unwrap.cjs.map +1 -7
  82. package/build/dom/wrap.cjs +17 -28
  83. package/build/dom/wrap.cjs.map +1 -7
  84. package/build/focusable.cjs +99 -76
  85. package/build/focusable.cjs.map +1 -7
  86. package/build/index.cjs +57 -38
  87. package/build/index.cjs.map +1 -7
  88. package/build/phrasing-content.cjs +163 -159
  89. package/build/phrasing-content.cjs.map +1 -7
  90. package/build/tabbable.cjs +123 -78
  91. package/build/tabbable.cjs.map +1 -7
  92. package/build/types.cjs +4 -18
  93. package/build/utils/assert-is-defined.cjs +8 -33
  94. package/build/utils/assert-is-defined.cjs.map +1 -7
  95. package/build-module/data-transfer.mjs +16 -14
  96. package/build-module/data-transfer.mjs.map +1 -7
  97. package/build-module/dom/caret-range-from-point.mjs +27 -18
  98. package/build-module/dom/caret-range-from-point.mjs.map +1 -7
  99. package/build-module/dom/clean-node-list.mjs +60 -105
  100. package/build-module/dom/clean-node-list.mjs.map +1 -7
  101. package/build-module/dom/compute-caret-rect.mjs +16 -12
  102. package/build-module/dom/compute-caret-rect.mjs.map +1 -7
  103. package/build-module/dom/document-has-selection.mjs +13 -6
  104. package/build-module/dom/document-has-selection.mjs.map +1 -7
  105. package/build-module/dom/document-has-text-selection.mjs +20 -10
  106. package/build-module/dom/document-has-text-selection.mjs.map +1 -7
  107. package/build-module/dom/document-has-uncollapsed-selection.mjs +14 -6
  108. package/build-module/dom/document-has-uncollapsed-selection.mjs.map +1 -7
  109. package/build-module/dom/get-computed-style.mjs +10 -10
  110. package/build-module/dom/get-computed-style.mjs.map +1 -7
  111. package/build-module/dom/get-offset-parent.mjs +20 -16
  112. package/build-module/dom/get-offset-parent.mjs.map +1 -7
  113. package/build-module/dom/get-range-height.mjs +14 -11
  114. package/build-module/dom/get-range-height.mjs.map +1 -7
  115. package/build-module/dom/get-rectangle-from-range.mjs +78 -108
  116. package/build-module/dom/get-rectangle-from-range.mjs.map +1 -7
  117. package/build-module/dom/get-scroll-container.mjs +28 -28
  118. package/build-module/dom/get-scroll-container.mjs.map +1 -7
  119. package/build-module/dom/hidden-caret-range-from-point.mjs +28 -19
  120. package/build-module/dom/hidden-caret-range-from-point.mjs.map +1 -7
  121. package/build-module/dom/index.mjs +28 -58
  122. package/build-module/dom/input-field-has-uncollapsed-selection.mjs +28 -20
  123. package/build-module/dom/input-field-has-uncollapsed-selection.mjs.map +1 -7
  124. package/build-module/dom/insert-after.mjs +13 -7
  125. package/build-module/dom/insert-after.mjs.map +1 -7
  126. package/build-module/dom/is-edge.mjs +53 -69
  127. package/build-module/dom/is-edge.mjs.map +1 -7
  128. package/build-module/dom/is-element.mjs +8 -5
  129. package/build-module/dom/is-element.mjs.map +1 -7
  130. package/build-module/dom/is-empty.mjs +19 -17
  131. package/build-module/dom/is-empty.mjs.map +1 -7
  132. package/build-module/dom/is-entirely-selected.mjs +51 -44
  133. package/build-module/dom/is-entirely-selected.mjs.map +1 -7
  134. package/build-module/dom/is-form-element.mjs +15 -11
  135. package/build-module/dom/is-form-element.mjs.map +1 -7
  136. package/build-module/dom/is-horizontal-edge.mjs +13 -6
  137. package/build-module/dom/is-horizontal-edge.mjs.map +1 -7
  138. package/build-module/dom/is-html-input-element.mjs +8 -5
  139. package/build-module/dom/is-html-input-element.mjs.map +1 -7
  140. package/build-module/dom/is-input-or-text-area.mjs +8 -5
  141. package/build-module/dom/is-input-or-text-area.mjs.map +1 -7
  142. package/build-module/dom/is-number-input.mjs +16 -10
  143. package/build-module/dom/is-number-input.mjs.map +1 -7
  144. package/build-module/dom/is-rtl.mjs +12 -6
  145. package/build-module/dom/is-rtl.mjs.map +1 -7
  146. package/build-module/dom/is-selection-forward.mjs +22 -19
  147. package/build-module/dom/is-selection-forward.mjs.map +1 -7
  148. package/build-module/dom/is-text-field.mjs +27 -20
  149. package/build-module/dom/is-text-field.mjs.map +1 -7
  150. package/build-module/dom/is-vertical-edge.mjs +13 -6
  151. package/build-module/dom/is-vertical-edge.mjs.map +1 -7
  152. package/build-module/dom/place-caret-at-edge.mjs +51 -52
  153. package/build-module/dom/place-caret-at-edge.mjs.map +1 -7
  154. package/build-module/dom/place-caret-at-horizontal-edge.mjs +11 -6
  155. package/build-module/dom/place-caret-at-horizontal-edge.mjs.map +1 -7
  156. package/build-module/dom/place-caret-at-vertical-edge.mjs +12 -6
  157. package/build-module/dom/place-caret-at-vertical-edge.mjs.map +1 -7
  158. package/build-module/dom/remove-invalid-html.mjs +17 -9
  159. package/build-module/dom/remove-invalid-html.mjs.map +1 -7
  160. package/build-module/dom/remove.mjs +11 -7
  161. package/build-module/dom/remove.mjs.map +1 -7
  162. package/build-module/dom/replace-tag.mjs +17 -12
  163. package/build-module/dom/replace-tag.mjs.map +1 -7
  164. package/build-module/dom/replace.mjs +13 -8
  165. package/build-module/dom/replace.mjs.map +1 -7
  166. package/build-module/dom/safe-html.mjs +27 -24
  167. package/build-module/dom/safe-html.mjs.map +1 -7
  168. package/build-module/dom/scroll-if-no-range.mjs +20 -13
  169. package/build-module/dom/scroll-if-no-range.mjs.map +1 -7
  170. package/build-module/dom/strip-html.mjs +15 -9
  171. package/build-module/dom/strip-html.mjs.map +1 -7
  172. package/build-module/dom/types.mjs +0 -1
  173. package/build-module/dom/unwrap.mjs +13 -11
  174. package/build-module/dom/unwrap.mjs.map +1 -7
  175. package/build-module/dom/wrap.mjs +13 -8
  176. package/build-module/dom/wrap.mjs.map +1 -7
  177. package/build-module/focusable.mjs +95 -52
  178. package/build-module/focusable.mjs.map +1 -7
  179. package/build-module/index.mjs +11 -5
  180. package/build-module/index.mjs.map +1 -7
  181. package/build-module/phrasing-content.mjs +157 -133
  182. package/build-module/phrasing-content.mjs.map +1 -7
  183. package/build-module/tabbable.mjs +116 -51
  184. package/build-module/tabbable.mjs.map +1 -7
  185. package/build-module/types.mjs +0 -1
  186. package/build-module/utils/assert-is-defined.mjs +4 -9
  187. package/build-module/utils/assert-is-defined.mjs.map +1 -7
  188. package/build-types/dom/clean-node-list.d.ts +2 -2
  189. package/build-types/dom/clean-node-list.d.ts.map +1 -1
  190. package/build-types/dom/is-edge.d.ts.map +1 -1
  191. package/build-types/dom/remove-invalid-html.d.ts +4 -4
  192. package/build-types/dom/remove-invalid-html.d.ts.map +1 -1
  193. package/package.json +4 -4
  194. package/src/dom/clean-node-list.ts +2 -2
  195. package/src/dom/is-edge.ts +35 -43
  196. package/src/dom/remove-invalid-html.ts +4 -4
  197. package/src/dom/test/{get-rectangle-from-range.browser.test.js → get-rectangle-from-range.browser.test.ts} +25 -25
  198. package/src/test/{dom.jsdom.test.js → dom.jsdom.test.ts} +9 -6
  199. package/src/test/{focusable.browser.test.js → focusable.browser.test.ts} +14 -13
  200. package/src/test/{tabbable.browser.test.js → tabbable.browser.test.ts} +3 -2
  201. package/build/dom/index.cjs.map +0 -7
  202. package/build/dom/types.cjs.map +0 -7
  203. package/build/types.cjs.map +0 -7
  204. package/build-module/dom/index.mjs.map +0 -7
  205. package/build-module/dom/types.mjs.map +0 -7
  206. package/build-module/types.mjs.map +0 -7
  207. /package/src/dom/test/{safe-html.jsdom.test.js → safe-html.jsdom.test.ts} +0 -0
  208. /package/src/dom/test/{strip-html.jsdom.test.js → strip-html.jsdom.test.ts} +0 -0
  209. /package/src/test/{focusable-area.jsdom.test.js → focusable-area.jsdom.test.ts} +0 -0
  210. /package/src/test/{utils.js → utils.ts} +0 -0
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/input-field-has-uncollapsed-selection.ts"],
4
- "sourcesContent": ["import isTextField from './is-text-field';\nimport isHTMLInputElement from './is-html-input-element';\n\n/**\n * Check whether the given input field or textarea contains a (uncollapsed)\n * selection of text.\n *\n * CAVEAT: Only specific text-based HTML inputs support the selection APIs\n * needed to determine whether they have a collapsed or uncollapsed selection.\n * This function defaults to returning `true` when the selection cannot be\n * inspected, such as with `<input type=\"time\">`. The rationale is that this\n * should cause the block editor to defer to the browser's native selection\n * handling (e.g. copying and pasting), thereby reducing friction for the user.\n *\n * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply\n *\n * @param element The HTML element.\n *\n * @return Whether the input/textarea element has some \"selection\".\n */\nexport default function inputFieldHasUncollapsedSelection(\n\telement: Element\n): boolean {\n\tif ( ! isHTMLInputElement( element ) && ! isTextField( element ) ) {\n\t\treturn false;\n\t}\n\n\t// Safari throws a type error when trying to get `selectionStart` and\n\t// `selectionEnd` on non-text <input> elements, so a try/catch construct is\n\t// necessary.\n\ttry {\n\t\tconst { selectionStart, selectionEnd } = element as\n\t\t\tHTMLInputElement | HTMLTextAreaElement;\n\t\treturn (\n\t\t\t// `null` means the input type doesn't implement selection, thus we\n\t\t\t// cannot determine whether the selection is collapsed, so we\n\t\t\t// default to true.\n\t\t\tselectionStart === null ||\n\t\t\t// when not null, compare the two points\n\t\t\tselectionStart !== selectionEnd\n\t\t);\n\t} catch {\n\t\t// This is Safari's way of saying that the input type doesn't implement\n\t\t// selection, so we default to true.\n\t\treturn true;\n\t}\n}\n"],
5
- "mappings": ";AAAA,OAAO,iBAAiB;AACxB,OAAO,wBAAwB;AAmBhB,SAAR,kCACN,SACU;AACV,MAAK,CAAE,mBAAoB,OAAQ,KAAK,CAAE,YAAa,OAAQ,GAAI;AAClE,WAAO;AAAA,EACR;AAKA,MAAI;AACH,UAAM,EAAE,gBAAgB,aAAa,IAAI;AAEzC;AAAA;AAAA;AAAA;AAAA,MAIC,mBAAmB;AAAA,MAEnB,mBAAmB;AAAA;AAAA,EAErB,QAAQ;AAGP,WAAO;AAAA,EACR;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"input-field-has-uncollapsed-selection.mjs","names":[],"sources":["../../src/dom/input-field-has-uncollapsed-selection.ts"],"sourcesContent":["import isTextField from './is-text-field';\nimport isHTMLInputElement from './is-html-input-element';\n\n/**\n * Check whether the given input field or textarea contains a (uncollapsed)\n * selection of text.\n *\n * CAVEAT: Only specific text-based HTML inputs support the selection APIs\n * needed to determine whether they have a collapsed or uncollapsed selection.\n * This function defaults to returning `true` when the selection cannot be\n * inspected, such as with `<input type=\"time\">`. The rationale is that this\n * should cause the block editor to defer to the browser's native selection\n * handling (e.g. copying and pasting), thereby reducing friction for the user.\n *\n * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply\n *\n * @param element The HTML element.\n *\n * @return Whether the input/textarea element has some \"selection\".\n */\nexport default function inputFieldHasUncollapsedSelection(\n\telement: Element\n): boolean {\n\tif ( ! isHTMLInputElement( element ) && ! isTextField( element ) ) {\n\t\treturn false;\n\t}\n\n\t// Safari throws a type error when trying to get `selectionStart` and\n\t// `selectionEnd` on non-text <input> elements, so a try/catch construct is\n\t// necessary.\n\ttry {\n\t\tconst { selectionStart, selectionEnd } = element as\n\t\t\tHTMLInputElement | HTMLTextAreaElement;\n\t\treturn (\n\t\t\t// `null` means the input type doesn't implement selection, thus we\n\t\t\t// cannot determine whether the selection is collapsed, so we\n\t\t\t// default to true.\n\t\t\tselectionStart === null ||\n\t\t\t// when not null, compare the two points\n\t\t\tselectionStart !== selectionEnd\n\t\t);\n\t} catch {\n\t\t// This is Safari's way of saying that the input type doesn't implement\n\t\t// selection, so we default to true.\n\t\treturn true;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAwB,kCACvB,SACU;CACV,IAAK,CAAE,mBAAoB,OAAQ,KAAK,CAAE,YAAa,OAAQ,GAC9D,OAAO;CAMR,IAAI;EACH,MAAM,EAAE,gBAAgB,iBAAiB;EAEzC,OAIC,mBAAmB,QAEnB,mBAAmB;CAErB,QAAQ;EAGP,OAAO;CACR;AACD"}
@@ -1,10 +1,16 @@
1
- // packages/dom/src/dom/insert-after.ts
2
1
  import { assertIsDefined } from "../utils/assert-is-defined.mjs";
2
+ // packages/dom/src/dom/insert-after.ts
3
+ /**
4
+ * Given two DOM nodes, inserts the former in the DOM as the next sibling of
5
+ * the latter.
6
+ *
7
+ * @param newNode Node to be inserted.
8
+ * @param referenceNode Node after which to perform the insertion.
9
+ */
3
10
  function insertAfter(newNode, referenceNode) {
4
- assertIsDefined(referenceNode.parentNode, "referenceNode.parentNode");
5
- referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
11
+ assertIsDefined(referenceNode.parentNode, "referenceNode.parentNode");
12
+ referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
6
13
  }
7
- export {
8
- insertAfter as default
9
- };
10
- //# sourceMappingURL=insert-after.mjs.map
14
+ export { insertAfter as default };
15
+
16
+ //# sourceMappingURL=insert-after.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/insert-after.ts"],
4
- "sourcesContent": ["import { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Given two DOM nodes, inserts the former in the DOM as the next sibling of\n * the latter.\n *\n * @param newNode Node to be inserted.\n * @param referenceNode Node after which to perform the insertion.\n */\nexport default function insertAfter(\n\tnewNode: Node,\n\treferenceNode: Node\n): void {\n\tassertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );\n\treferenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );\n}\n"],
5
- "mappings": ";AAAA,SAAS,uBAAuB;AASjB,SAAR,YACN,SACA,eACO;AACP,kBAAiB,cAAc,YAAY,0BAA2B;AACtE,gBAAc,WAAW,aAAc,SAAS,cAAc,WAAY;AAC3E;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"insert-after.mjs","names":[],"sources":["../../src/dom/insert-after.ts"],"sourcesContent":["import { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Given two DOM nodes, inserts the former in the DOM as the next sibling of\n * the latter.\n *\n * @param newNode Node to be inserted.\n * @param referenceNode Node after which to perform the insertion.\n */\nexport default function insertAfter(\n\tnewNode: Node,\n\treferenceNode: Node\n): void {\n\tassertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );\n\treferenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );\n}\n"],"mappings":";;;;;;;;;AASA,SAAwB,YACvB,SACA,eACO;CACP,gBAAiB,cAAc,YAAY,0BAA2B;CACtE,cAAc,WAAW,aAAc,SAAS,cAAc,WAAY;AAC3E"}
@@ -1,4 +1,3 @@
1
- // packages/dom/src/dom/is-edge.ts
2
1
  import isRTL from "./is-rtl.mjs";
3
2
  import getRangeHeight from "./get-range-height.mjs";
4
3
  import getRectangleFromRange from "./get-rectangle-from-range.mjs";
@@ -6,73 +5,58 @@ import isSelectionForward from "./is-selection-forward.mjs";
6
5
  import hiddenCaretRangeFromPoint from "./hidden-caret-range-from-point.mjs";
7
6
  import { assertIsDefined } from "../utils/assert-is-defined.mjs";
8
7
  import isInputOrTextArea from "./is-input-or-text-area.mjs";
9
- import { scrollIfNoRange } from "./scroll-if-no-range.mjs";
8
+ // packages/dom/src/dom/is-edge.ts
9
+ /**
10
+ * Check whether the selection is at the edge of the container. Checks for
11
+ * horizontal position by default. Set `onlyVertical` to true to check only
12
+ * vertically.
13
+ *
14
+ * @param container Focusable element.
15
+ * @param isReverse Set to true to check left, false to check right.
16
+ * @param onlyVertical Set to true to check only vertical position.
17
+ *
18
+ * @return True if at the edge, false if not.
19
+ */
10
20
  function isEdge(container, isReverse, onlyVertical = false) {
11
- if (isInputOrTextArea(container) && typeof container.selectionStart === "number") {
12
- if (container.selectionStart !== container.selectionEnd) {
13
- return false;
14
- }
15
- if (isReverse) {
16
- return container.selectionStart === 0;
17
- }
18
- return container.value.length === container.selectionStart;
19
- }
20
- if (!container.isContentEditable) {
21
- return true;
22
- }
23
- const { ownerDocument } = container;
24
- const { defaultView } = ownerDocument;
25
- assertIsDefined(defaultView, "defaultView");
26
- const selection = defaultView.getSelection();
27
- if (!selection || !selection.rangeCount) {
28
- return false;
29
- }
30
- const range = selection.getRangeAt(0);
31
- const collapsedRange = range.cloneRange();
32
- const isForward = isSelectionForward(selection);
33
- const isCollapsed = selection.isCollapsed;
34
- if (!isCollapsed) {
35
- collapsedRange.collapse(!isForward);
36
- }
37
- const collapsedRangeRect = getRectangleFromRange(collapsedRange);
38
- const rangeRect = getRectangleFromRange(range);
39
- if (!collapsedRangeRect || !rangeRect) {
40
- return false;
41
- }
42
- const rangeHeight = getRangeHeight(range);
43
- if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) {
44
- return false;
45
- }
46
- const isReverseDir = isRTL(container) ? !isReverse : isReverse;
47
- const containerRect = container.getBoundingClientRect();
48
- const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
49
- const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
50
- const isFarFromVerticalEdge = (y < 0 || y > defaultView.innerHeight) && rangeRect.top >= 0 && rangeRect.bottom <= defaultView.innerHeight;
51
- const isFarFromHorizontalEdge = (x < 0 || x > defaultView.innerWidth) && rangeRect.left >= 0 && rangeRect.right <= defaultView.innerWidth;
52
- if (isFarFromVerticalEdge || !onlyVertical && isFarFromHorizontalEdge) {
53
- return false;
54
- }
55
- const testRange = scrollIfNoRange(
56
- container,
57
- isReverse,
58
- () => hiddenCaretRangeFromPoint(ownerDocument, x, y, container)
59
- );
60
- if (!testRange) {
61
- return false;
62
- }
63
- const testRect = getRectangleFromRange(testRange);
64
- if (!testRect) {
65
- return false;
66
- }
67
- const verticalSide = isReverse ? "top" : "bottom";
68
- const horizontalSide = isReverseDir ? "left" : "right";
69
- const verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
70
- const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide];
71
- const hasVerticalDiff = Math.abs(verticalDiff) <= 1;
72
- const hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
73
- return onlyVertical ? hasVerticalDiff : hasVerticalDiff && hasHorizontalDiff;
21
+ if (isInputOrTextArea(container) && typeof container.selectionStart === "number") {
22
+ if (container.selectionStart !== container.selectionEnd) return false;
23
+ if (isReverse) return container.selectionStart === 0;
24
+ return container.value.length === container.selectionStart;
25
+ }
26
+ if (!container.isContentEditable) return true;
27
+ const { ownerDocument } = container;
28
+ const { defaultView } = ownerDocument;
29
+ assertIsDefined(defaultView, "defaultView");
30
+ const selection = defaultView.getSelection();
31
+ if (!selection || !selection.rangeCount) return false;
32
+ const range = selection.getRangeAt(0);
33
+ const collapsedRange = range.cloneRange();
34
+ const isForward = isSelectionForward(selection);
35
+ const isCollapsed = selection.isCollapsed;
36
+ if (!isCollapsed) collapsedRange.collapse(!isForward);
37
+ const collapsedRangeRect = getRectangleFromRange(collapsedRange);
38
+ const rangeRect = getRectangleFromRange(range);
39
+ if (!collapsedRangeRect || !rangeRect) return false;
40
+ const rangeHeight = getRangeHeight(range);
41
+ if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) return false;
42
+ const contentRange = ownerDocument.createRange();
43
+ contentRange.selectNodeContents(container);
44
+ if (Array.from(contentRange.getClientRects()).some((rect) => rect.height > 0 && (isReverse ? rect.bottom <= rangeRect.top + 1 : rect.top >= rangeRect.bottom - 1))) return false;
45
+ if (onlyVertical) return true;
46
+ const isReverseDir = isRTL(container) ? !isReverse : isReverse;
47
+ const containerRect = container.getBoundingClientRect();
48
+ const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
49
+ const y = isReverse ? rangeRect.top + 1 : rangeRect.bottom - 1;
50
+ const testRange = hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
51
+ if (!testRange || !container.contains(testRange.startContainer)) return false;
52
+ const testRect = getRectangleFromRange(testRange);
53
+ if (!testRect) return false;
54
+ const verticalSide = isReverse ? "top" : "bottom";
55
+ const horizontalSide = isReverseDir ? "left" : "right";
56
+ const verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
57
+ const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide];
58
+ return Math.abs(verticalDiff) <= 1 && Math.abs(horizontalDiff) <= 1;
74
59
  }
75
- export {
76
- isEdge as default
77
- };
78
- //# sourceMappingURL=is-edge.mjs.map
60
+ export { isEdge as default };
61
+
62
+ //# sourceMappingURL=is-edge.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/is-edge.ts"],
4
- "sourcesContent": ["import isRTL from './is-rtl';\nimport getRangeHeight from './get-range-height';\nimport getRectangleFromRange from './get-rectangle-from-range';\nimport isSelectionForward from './is-selection-forward';\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\nimport { scrollIfNoRange } from './scroll-if-no-range';\n\n/**\n * Check whether the selection is at the edge of the container. Checks for\n * horizontal position by default. Set `onlyVertical` to true to check only\n * vertically.\n *\n * @param container Focusable element.\n * @param isReverse Set to true to check left, false to check right.\n * @param onlyVertical Set to true to check only vertical position.\n *\n * @return True if at the edge, false if not.\n */\nexport default function isEdge(\n\tcontainer: HTMLElement,\n\tisReverse: boolean,\n\tonlyVertical: boolean = false\n): boolean {\n\tif (\n\t\tisInputOrTextArea( container ) &&\n\t\ttypeof container.selectionStart === 'number'\n\t) {\n\t\tif ( container.selectionStart !== container.selectionEnd ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\treturn container.selectionStart === 0;\n\t\t}\n\n\t\treturn container.value.length === container.selectionStart;\n\t}\n\n\tif ( ! container.isContentEditable ) {\n\t\treturn true;\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\n\tif ( ! selection || ! selection.rangeCount ) {\n\t\treturn false;\n\t}\n\n\tconst range = selection.getRangeAt( 0 );\n\tconst collapsedRange = range.cloneRange();\n\tconst isForward = isSelectionForward( selection );\n\tconst isCollapsed = selection.isCollapsed;\n\n\t// Collapse in direction of selection.\n\tif ( ! isCollapsed ) {\n\t\tcollapsedRange.collapse( ! isForward );\n\t}\n\n\tconst collapsedRangeRect = getRectangleFromRange( collapsedRange );\n\tconst rangeRect = getRectangleFromRange( range );\n\n\tif ( ! collapsedRangeRect || ! rangeRect ) {\n\t\treturn false;\n\t}\n\n\t// Only consider the multiline selection at the edge if the direction is\n\t// towards the edge. The selection is multiline if it is taller than the\n\t// collapsed selection.\n\tconst rangeHeight = getRangeHeight( range );\n\tif (\n\t\t! isCollapsed &&\n\t\trangeHeight &&\n\t\trangeHeight > collapsedRangeRect.height &&\n\t\tisForward === isReverse\n\t) {\n\t\treturn false;\n\t}\n\n\t// In the case of RTL scripts, the horizontal edge is at the opposite side.\n\tconst isReverseDir = isRTL( container ) ? ! isReverse : isReverse;\n\tconst containerRect = container.getBoundingClientRect();\n\n\t// To check if a selection is at the edge, we insert a test selection at the\n\t// edge of the container and check if the selections have the same vertical\n\t// or horizontal position. If they do, the selection is at the edge.\n\t// This method proves to be better than a DOM-based calculation for the\n\t// horizontal edge, since it ignores empty textnodes and a trailing line\n\t// break element. In other words, we need to check visual positioning, not\n\t// DOM positioning.\n\t// It also proves better than using the computed style for the vertical\n\t// edge, because we cannot know the padding and line height reliably in\n\t// pixels. `getComputedStyle` may return a value with different units.\n\tconst x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;\n\tconst y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;\n\n\t// The test point can only be hit-tested when it is within the viewport\n\t// (`caretRangeFromPoint` returns nothing for a point outside it, upon\n\t// which `scrollIfNoRange` scrolls the container's edge into view to\n\t// measure, e.g. on every arrow press within a container taller than the\n\t// viewport). When the edge is outside the viewport and the selection is\n\t// within it, they are at least a viewport boundary apart along that\n\t// axis, so the selection cannot be at the edge. Check each axis\n\t// separately: the vertical check must not be short-circuited by a\n\t// horizontally overflowing container, and vice versa.\n\tconst isFarFromVerticalEdge =\n\t\t( y < 0 || y > defaultView.innerHeight ) &&\n\t\trangeRect.top >= 0 &&\n\t\trangeRect.bottom <= defaultView.innerHeight;\n\tconst isFarFromHorizontalEdge =\n\t\t( x < 0 || x > defaultView.innerWidth ) &&\n\t\trangeRect.left >= 0 &&\n\t\trangeRect.right <= defaultView.innerWidth;\n\n\tif (\n\t\tisFarFromVerticalEdge ||\n\t\t( ! onlyVertical && isFarFromHorizontalEdge )\n\t) {\n\t\treturn false;\n\t}\n\n\tconst testRange = scrollIfNoRange( container, isReverse, () =>\n\t\thiddenCaretRangeFromPoint( ownerDocument, x, y, container )\n\t);\n\n\tif ( ! testRange ) {\n\t\treturn false;\n\t}\n\n\tconst testRect = getRectangleFromRange( testRange );\n\n\tif ( ! testRect ) {\n\t\treturn false;\n\t}\n\n\tconst verticalSide = isReverse ? 'top' : 'bottom';\n\tconst horizontalSide = isReverseDir ? 'left' : 'right';\n\tconst verticalDiff = testRect[ verticalSide ] - rangeRect[ verticalSide ];\n\tconst horizontalDiff =\n\t\ttestRect[ horizontalSide ] - collapsedRangeRect[ horizontalSide ];\n\n\t// Allow the position to be 1px off.\n\tconst hasVerticalDiff = Math.abs( verticalDiff ) <= 1;\n\tconst hasHorizontalDiff = Math.abs( horizontalDiff ) <= 1;\n\n\treturn onlyVertical\n\t\t? hasVerticalDiff\n\t\t: hasVerticalDiff && hasHorizontalDiff;\n}\n"],
5
- "mappings": ";AAAA,OAAO,WAAW;AAClB,OAAO,oBAAoB;AAC3B,OAAO,2BAA2B;AAClC,OAAO,wBAAwB;AAC/B,OAAO,+BAA+B;AACtC,SAAS,uBAAuB;AAChC,OAAO,uBAAuB;AAC9B,SAAS,uBAAuB;AAajB,SAAR,OACN,WACA,WACA,eAAwB,OACd;AACV,MACC,kBAAmB,SAAU,KAC7B,OAAO,UAAU,mBAAmB,UACnC;AACD,QAAK,UAAU,mBAAmB,UAAU,cAAe;AAC1D,aAAO;AAAA,IACR;AAEA,QAAK,WAAY;AAChB,aAAO,UAAU,mBAAmB;AAAA,IACrC;AAEA,WAAO,UAAU,MAAM,WAAW,UAAU;AAAA,EAC7C;AAEA,MAAK,CAAE,UAAU,mBAAoB;AACpC,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,EAAE,YAAY,IAAI;AAExB,kBAAiB,aAAa,aAAc;AAC5C,QAAM,YAAY,YAAY,aAAa;AAE3C,MAAK,CAAE,aAAa,CAAE,UAAU,YAAa;AAC5C,WAAO;AAAA,EACR;AAEA,QAAM,QAAQ,UAAU,WAAY,CAAE;AACtC,QAAM,iBAAiB,MAAM,WAAW;AACxC,QAAM,YAAY,mBAAoB,SAAU;AAChD,QAAM,cAAc,UAAU;AAG9B,MAAK,CAAE,aAAc;AACpB,mBAAe,SAAU,CAAE,SAAU;AAAA,EACtC;AAEA,QAAM,qBAAqB,sBAAuB,cAAe;AACjE,QAAM,YAAY,sBAAuB,KAAM;AAE/C,MAAK,CAAE,sBAAsB,CAAE,WAAY;AAC1C,WAAO;AAAA,EACR;AAKA,QAAM,cAAc,eAAgB,KAAM;AAC1C,MACC,CAAE,eACF,eACA,cAAc,mBAAmB,UACjC,cAAc,WACb;AACD,WAAO;AAAA,EACR;AAGA,QAAM,eAAe,MAAO,SAAU,IAAI,CAAE,YAAY;AACxD,QAAM,gBAAgB,UAAU,sBAAsB;AAYtD,QAAM,IAAI,eAAe,cAAc,OAAO,IAAI,cAAc,QAAQ;AACxE,QAAM,IAAI,YAAY,cAAc,MAAM,IAAI,cAAc,SAAS;AAWrE,QAAM,yBACH,IAAI,KAAK,IAAI,YAAY,gBAC3B,UAAU,OAAO,KACjB,UAAU,UAAU,YAAY;AACjC,QAAM,2BACH,IAAI,KAAK,IAAI,YAAY,eAC3B,UAAU,QAAQ,KAClB,UAAU,SAAS,YAAY;AAEhC,MACC,yBACE,CAAE,gBAAgB,yBACnB;AACD,WAAO;AAAA,EACR;AAEA,QAAM,YAAY;AAAA,IAAiB;AAAA,IAAW;AAAA,IAAW,MACxD,0BAA2B,eAAe,GAAG,GAAG,SAAU;AAAA,EAC3D;AAEA,MAAK,CAAE,WAAY;AAClB,WAAO;AAAA,EACR;AAEA,QAAM,WAAW,sBAAuB,SAAU;AAElD,MAAK,CAAE,UAAW;AACjB,WAAO;AAAA,EACR;AAEA,QAAM,eAAe,YAAY,QAAQ;AACzC,QAAM,iBAAiB,eAAe,SAAS;AAC/C,QAAM,eAAe,SAAU,YAAa,IAAI,UAAW,YAAa;AACxE,QAAM,iBACL,SAAU,cAAe,IAAI,mBAAoB,cAAe;AAGjE,QAAM,kBAAkB,KAAK,IAAK,YAAa,KAAK;AACpD,QAAM,oBAAoB,KAAK,IAAK,cAAe,KAAK;AAExD,SAAO,eACJ,kBACA,mBAAmB;AACvB;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"is-edge.mjs","names":[],"sources":["../../src/dom/is-edge.ts"],"sourcesContent":["import isRTL from './is-rtl';\nimport getRangeHeight from './get-range-height';\nimport getRectangleFromRange from './get-rectangle-from-range';\nimport isSelectionForward from './is-selection-forward';\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\n\n/**\n * Check whether the selection is at the edge of the container. Checks for\n * horizontal position by default. Set `onlyVertical` to true to check only\n * vertically.\n *\n * @param container Focusable element.\n * @param isReverse Set to true to check left, false to check right.\n * @param onlyVertical Set to true to check only vertical position.\n *\n * @return True if at the edge, false if not.\n */\nexport default function isEdge(\n\tcontainer: HTMLElement,\n\tisReverse: boolean,\n\tonlyVertical: boolean = false\n): boolean {\n\tif (\n\t\tisInputOrTextArea( container ) &&\n\t\ttypeof container.selectionStart === 'number'\n\t) {\n\t\tif ( container.selectionStart !== container.selectionEnd ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\treturn container.selectionStart === 0;\n\t\t}\n\n\t\treturn container.value.length === container.selectionStart;\n\t}\n\n\tif ( ! container.isContentEditable ) {\n\t\treturn true;\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\n\tif ( ! selection || ! selection.rangeCount ) {\n\t\treturn false;\n\t}\n\n\tconst range = selection.getRangeAt( 0 );\n\tconst collapsedRange = range.cloneRange();\n\tconst isForward = isSelectionForward( selection );\n\tconst isCollapsed = selection.isCollapsed;\n\n\t// Collapse in direction of selection.\n\tif ( ! isCollapsed ) {\n\t\tcollapsedRange.collapse( ! isForward );\n\t}\n\n\tconst collapsedRangeRect = getRectangleFromRange( collapsedRange );\n\tconst rangeRect = getRectangleFromRange( range );\n\n\tif ( ! collapsedRangeRect || ! rangeRect ) {\n\t\treturn false;\n\t}\n\n\t// Only consider the multiline selection at the edge if the direction is\n\t// towards the edge. The selection is multiline if it is taller than the\n\t// collapsed selection.\n\tconst rangeHeight = getRangeHeight( range );\n\tif (\n\t\t! isCollapsed &&\n\t\trangeHeight &&\n\t\trangeHeight > collapsedRangeRect.height &&\n\t\tisForward === isReverse\n\t) {\n\t\treturn false;\n\t}\n\n\t// A line above the selection (or below, when going down) means it is not\n\t// at the vertical edge. Unlike hit-testing a point, a range measures\n\t// lines outside the viewport too.\n\tconst contentRange = ownerDocument.createRange();\n\tcontentRange.selectNodeContents( container );\n\tconst hasLineBeyond = Array.from( contentRange.getClientRects() ).some(\n\t\t( rect ) =>\n\t\t\trect.height > 0 &&\n\t\t\t( isReverse\n\t\t\t\t? rect.bottom <= rangeRect.top + 1\n\t\t\t\t: rect.top >= rangeRect.bottom - 1 )\n\t);\n\n\tif ( hasLineBeyond ) {\n\t\treturn false;\n\t}\n\n\tif ( onlyVertical ) {\n\t\treturn true;\n\t}\n\n\t// In the case of RTL scripts, the horizontal edge is at the opposite side.\n\tconst isReverseDir = isRTL( container ) ? ! isReverse : isReverse;\n\tconst containerRect = container.getBoundingClientRect();\n\n\t// The selection is on the edge line. To check if it is at the horizontal\n\t// edge of that line, we hit-test a point at the container's edge on that\n\t// line and check if the caret there has the same position. This proves\n\t// better than a DOM-based calculation, since it ignores empty text nodes\n\t// and a trailing line break element. The line is within the viewport when\n\t// the selection is; otherwise the browser handles the key.\n\tconst x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;\n\tconst y = isReverse ? rangeRect.top + 1 : rangeRect.bottom - 1;\n\n\tconst testRange = hiddenCaretRangeFromPoint(\n\t\townerDocument,\n\t\tx,\n\t\ty,\n\t\tcontainer\n\t);\n\n\tif ( ! testRange || ! container.contains( testRange.startContainer ) ) {\n\t\treturn false;\n\t}\n\n\tconst testRect = getRectangleFromRange( testRange );\n\n\tif ( ! testRect ) {\n\t\treturn false;\n\t}\n\n\tconst verticalSide = isReverse ? 'top' : 'bottom';\n\tconst horizontalSide = isReverseDir ? 'left' : 'right';\n\tconst verticalDiff = testRect[ verticalSide ] - rangeRect[ verticalSide ];\n\tconst horizontalDiff =\n\t\ttestRect[ horizontalSide ] - collapsedRangeRect[ horizontalSide ];\n\n\t// Allow the position to be 1px off.\n\tconst hasVerticalDiff = Math.abs( verticalDiff ) <= 1;\n\tconst hasHorizontalDiff = Math.abs( horizontalDiff ) <= 1;\n\n\treturn hasVerticalDiff && hasHorizontalDiff;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,SAAwB,OACvB,WACA,WACA,eAAwB,OACd;CACV,IACC,kBAAmB,SAAU,KAC7B,OAAO,UAAU,mBAAmB,UACnC;EACD,IAAK,UAAU,mBAAmB,UAAU,cAC3C,OAAO;EAGR,IAAK,WACJ,OAAO,UAAU,mBAAmB;EAGrC,OAAO,UAAU,MAAM,WAAW,UAAU;CAC7C;CAEA,IAAK,CAAE,UAAU,mBAChB,OAAO;CAGR,MAAM,EAAE,kBAAkB;CAC1B,MAAM,EAAE,gBAAgB;CAExB,gBAAiB,aAAa,aAAc;CAC5C,MAAM,YAAY,YAAY,aAAa;CAE3C,IAAK,CAAE,aAAa,CAAE,UAAU,YAC/B,OAAO;CAGR,MAAM,QAAQ,UAAU,WAAY,CAAE;CACtC,MAAM,iBAAiB,MAAM,WAAW;CACxC,MAAM,YAAY,mBAAoB,SAAU;CAChD,MAAM,cAAc,UAAU;CAG9B,IAAK,CAAE,aACN,eAAe,SAAU,CAAE,SAAU;CAGtC,MAAM,qBAAqB,sBAAuB,cAAe;CACjE,MAAM,YAAY,sBAAuB,KAAM;CAE/C,IAAK,CAAE,sBAAsB,CAAE,WAC9B,OAAO;CAMR,MAAM,cAAc,eAAgB,KAAM;CAC1C,IACC,CAAE,eACF,eACA,cAAc,mBAAmB,UACjC,cAAc,WAEd,OAAO;CAMR,MAAM,eAAe,cAAc,YAAY;CAC/C,aAAa,mBAAoB,SAAU;CAS3C,IARsB,MAAM,KAAM,aAAa,eAAe,CAAE,CAAC,CAAC,MAC/D,SACD,KAAK,SAAS,MACZ,YACC,KAAK,UAAU,UAAU,MAAM,IAC/B,KAAK,OAAO,UAAU,SAAS,EAGnB,GAChB,OAAO;CAGR,IAAK,cACJ,OAAO;CAIR,MAAM,eAAe,MAAO,SAAU,IAAI,CAAE,YAAY;CACxD,MAAM,gBAAgB,UAAU,sBAAsB;CAQtD,MAAM,IAAI,eAAe,cAAc,OAAO,IAAI,cAAc,QAAQ;CACxE,MAAM,IAAI,YAAY,UAAU,MAAM,IAAI,UAAU,SAAS;CAE7D,MAAM,YAAY,0BACjB,eACA,GACA,GACA,SACD;CAEA,IAAK,CAAE,aAAa,CAAE,UAAU,SAAU,UAAU,cAAe,GAClE,OAAO;CAGR,MAAM,WAAW,sBAAuB,SAAU;CAElD,IAAK,CAAE,UACN,OAAO;CAGR,MAAM,eAAe,YAAY,QAAQ;CACzC,MAAM,iBAAiB,eAAe,SAAS;CAC/C,MAAM,eAAe,SAAU,gBAAiB,UAAW;CAC3D,MAAM,iBACL,SAAU,kBAAmB,mBAAoB;CAMlD,OAHwB,KAAK,IAAK,YAAa,KAAK,KAC1B,KAAK,IAAK,cAAe,KAAK;AAGzD"}
@@ -1,8 +1,11 @@
1
1
  // packages/dom/src/dom/is-element.ts
2
+ /**
3
+ * @param {Node | null | undefined} node
4
+ * @return {node is Element} True if node is an Element node
5
+ */
2
6
  function isElement(node) {
3
- return !!node && node.nodeType === node.ELEMENT_NODE;
7
+ return !!node && node.nodeType === node.ELEMENT_NODE;
4
8
  }
5
- export {
6
- isElement as default
7
- };
8
- //# sourceMappingURL=is-element.mjs.map
9
+ export { isElement as default };
10
+
11
+ //# sourceMappingURL=is-element.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/is-element.ts"],
4
- "sourcesContent": ["/**\n * @param {Node | null | undefined} node\n * @return {node is Element} True if node is an Element node\n */\nexport default function isElement(\n\tnode: Node | null | undefined\n): node is Element {\n\treturn !! node && node.nodeType === node.ELEMENT_NODE;\n}\n"],
5
- "mappings": ";AAIe,SAAR,UACN,MACkB;AAClB,SAAO,CAAC,CAAE,QAAQ,KAAK,aAAa,KAAK;AAC1C;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"is-element.mjs","names":[],"sources":["../../src/dom/is-element.ts"],"sourcesContent":["/**\n * @param {Node | null | undefined} node\n * @return {node is Element} True if node is an Element node\n */\nexport default function isElement(\n\tnode: Node | null | undefined\n): node is Element {\n\treturn !! node && node.nodeType === node.ELEMENT_NODE;\n}\n"],"mappings":";;;;;AAIA,SAAwB,UACvB,MACkB;CAClB,OAAO,CAAC,CAAE,QAAQ,KAAK,aAAa,KAAK;AAC1C"}
@@ -1,20 +1,22 @@
1
1
  // packages/dom/src/dom/is-empty.ts
2
+ /**
3
+ * Recursively checks if an element is empty. An element is not empty if it
4
+ * contains text or contains elements with attributes such as images.
5
+ *
6
+ * @param element The element to check.
7
+ *
8
+ * @return Whether or not the element is empty.
9
+ */
2
10
  function isEmpty(element) {
3
- switch (element.nodeType) {
4
- case element.TEXT_NODE:
5
- return /^[ \f\n\r\t\v\u00a0]*$/.test(element.nodeValue || "");
6
- case element.ELEMENT_NODE:
7
- if (element.hasAttributes()) {
8
- return false;
9
- } else if (!element.hasChildNodes()) {
10
- return true;
11
- }
12
- return Array.from(element.childNodes).every(isEmpty);
13
- default:
14
- return true;
15
- }
11
+ switch (element.nodeType) {
12
+ case element.TEXT_NODE: return /^[ \f\n\r\t\v\u00a0]*$/.test(element.nodeValue || "");
13
+ case element.ELEMENT_NODE:
14
+ if (element.hasAttributes()) return false;
15
+ else if (!element.hasChildNodes()) return true;
16
+ return Array.from(element.childNodes).every(isEmpty);
17
+ default: return true;
18
+ }
16
19
  }
17
- export {
18
- isEmpty as default
19
- };
20
- //# sourceMappingURL=is-empty.mjs.map
20
+ export { isEmpty as default };
21
+
22
+ //# sourceMappingURL=is-empty.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/is-empty.ts"],
4
- "sourcesContent": ["/**\n * Recursively checks if an element is empty. An element is not empty if it\n * contains text or contains elements with attributes such as images.\n *\n * @param element The element to check.\n *\n * @return Whether or not the element is empty.\n */\nexport default function isEmpty( element: Node ): boolean {\n\tswitch ( element.nodeType ) {\n\t\tcase element.TEXT_NODE:\n\t\t\t// We cannot use \\s since it includes special spaces which we want\n\t\t\t// to preserve.\n\t\t\treturn /^[ \\f\\n\\r\\t\\v\\u00a0]*$/.test( element.nodeValue || '' );\n\t\tcase element.ELEMENT_NODE:\n\t\t\tif ( ( element as Element ).hasAttributes() ) {\n\t\t\t\treturn false;\n\t\t\t} else if ( ! element.hasChildNodes() ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn Array.from( element.childNodes ).every( isEmpty );\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n"],
5
- "mappings": ";AAQe,SAAR,QAA0B,SAAyB;AACzD,UAAS,QAAQ,UAAW;AAAA,IAC3B,KAAK,QAAQ;AAGZ,aAAO,yBAAyB,KAAM,QAAQ,aAAa,EAAG;AAAA,IAC/D,KAAK,QAAQ;AACZ,UAAO,QAAqB,cAAc,GAAI;AAC7C,eAAO;AAAA,MACR,WAAY,CAAE,QAAQ,cAAc,GAAI;AACvC,eAAO;AAAA,MACR;AAEA,aAAO,MAAM,KAAM,QAAQ,UAAW,EAAE,MAAO,OAAQ;AAAA,IACxD;AACC,aAAO;AAAA,EACT;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"is-empty.mjs","names":[],"sources":["../../src/dom/is-empty.ts"],"sourcesContent":["/**\n * Recursively checks if an element is empty. An element is not empty if it\n * contains text or contains elements with attributes such as images.\n *\n * @param element The element to check.\n *\n * @return Whether or not the element is empty.\n */\nexport default function isEmpty( element: Node ): boolean {\n\tswitch ( element.nodeType ) {\n\t\tcase element.TEXT_NODE:\n\t\t\t// We cannot use \\s since it includes special spaces which we want\n\t\t\t// to preserve.\n\t\t\treturn /^[ \\f\\n\\r\\t\\v\\u00a0]*$/.test( element.nodeValue || '' );\n\t\tcase element.ELEMENT_NODE:\n\t\t\tif ( ( element as Element ).hasAttributes() ) {\n\t\t\t\treturn false;\n\t\t\t} else if ( ! element.hasChildNodes() ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn Array.from( element.childNodes ).every( isEmpty );\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n"],"mappings":";;;;;;;;;AAQA,SAAwB,QAAS,SAAyB;CACzD,QAAS,QAAQ,UAAjB;EACC,KAAK,QAAQ,WAGZ,OAAO,yBAAyB,KAAM,QAAQ,aAAa,EAAG;EAC/D,KAAK,QAAQ;GACZ,IAAO,QAAqB,cAAc,GACzC,OAAO;QACD,IAAK,CAAE,QAAQ,cAAc,GACnC,OAAO;GAGR,OAAO,MAAM,KAAM,QAAQ,UAAW,CAAC,CAAC,MAAO,OAAQ;EACxD,SACC,OAAO;CACT;AACD"}
@@ -1,50 +1,57 @@
1
- // packages/dom/src/dom/is-entirely-selected.ts
2
1
  import { assertIsDefined } from "../utils/assert-is-defined.mjs";
3
2
  import isInputOrTextArea from "./is-input-or-text-area.mjs";
4
- var ZWNBSP = "\uFEFF";
3
+ // packages/dom/src/dom/is-entirely-selected.ts
4
+ /**
5
+ * Zero width non-breaking space, used as padding in the editable DOM tree when
6
+ * it is empty otherwise.
7
+ */
8
+ const ZWNBSP = "";
9
+ /**
10
+ * Check whether the contents of the element have been entirely selected.
11
+ * Returns true if there is no possibility of selection.
12
+ *
13
+ * @param element The element to check.
14
+ *
15
+ * @return True if entirely selected, false if not.
16
+ */
5
17
  function isEntirelySelected(element) {
6
- if (isInputOrTextArea(element)) {
7
- return element.selectionStart === 0 && element.value.length === element.selectionEnd;
8
- }
9
- if (!element.isContentEditable) {
10
- return true;
11
- }
12
- const text = element.textContent || "";
13
- if (text === "" || text === ZWNBSP) {
14
- return true;
15
- }
16
- const { ownerDocument } = element;
17
- const { defaultView } = ownerDocument;
18
- assertIsDefined(defaultView, "defaultView");
19
- const selection = defaultView.getSelection();
20
- assertIsDefined(selection, "selection");
21
- const range = selection.rangeCount ? selection.getRangeAt(0) : null;
22
- if (!range) {
23
- return true;
24
- }
25
- const { startContainer, endContainer, startOffset, endOffset } = range;
26
- if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) {
27
- return true;
28
- }
29
- const lastChild = element.lastChild;
30
- assertIsDefined(lastChild, "lastChild");
31
- const endContainerContentLength = endContainer.nodeType === endContainer.TEXT_NODE ? endContainer.data.length : endContainer.childNodes.length;
32
- return isDeepChild(startContainer, element, "firstChild") && isDeepChild(endContainer, element, "lastChild") && startOffset === 0 && endOffset === endContainerContentLength;
18
+ if (isInputOrTextArea(element)) return element.selectionStart === 0 && element.value.length === element.selectionEnd;
19
+ if (!element.isContentEditable) return true;
20
+ const text = element.textContent || "";
21
+ if (text === "" || text === ZWNBSP) return true;
22
+ const { ownerDocument } = element;
23
+ const { defaultView } = ownerDocument;
24
+ assertIsDefined(defaultView, "defaultView");
25
+ const selection = defaultView.getSelection();
26
+ assertIsDefined(selection, "selection");
27
+ const range = selection.rangeCount ? selection.getRangeAt(0) : null;
28
+ if (!range) return true;
29
+ const { startContainer, endContainer, startOffset, endOffset } = range;
30
+ if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) return true;
31
+ const lastChild = element.lastChild;
32
+ assertIsDefined(lastChild, "lastChild");
33
+ const endContainerContentLength = endContainer.nodeType === endContainer.TEXT_NODE ? endContainer.data.length : endContainer.childNodes.length;
34
+ return isDeepChild(startContainer, element, "firstChild") && isDeepChild(endContainer, element, "lastChild") && startOffset === 0 && endOffset === endContainerContentLength;
33
35
  }
36
+ /**
37
+ * Check whether the contents of the element have been entirely selected.
38
+ * Returns true if there is no possibility of selection.
39
+ *
40
+ * @param query The element to check.
41
+ * @param container The container that we suspect "query" may be a first or last child of.
42
+ * @param propName "firstChild" or "lastChild"
43
+ *
44
+ * @return True if query is a deep first/last child of container, false otherwise.
45
+ */
34
46
  function isDeepChild(query, container, propName) {
35
- let candidate = container;
36
- do {
37
- if (query === candidate) {
38
- return true;
39
- }
40
- candidate = candidate[propName];
41
- while (candidate && candidate.nodeType === candidate.TEXT_NODE && candidate.nodeValue === "") {
42
- candidate = candidate[propName === "lastChild" ? "previousSibling" : "nextSibling"];
43
- }
44
- } while (candidate);
45
- return false;
47
+ let candidate = container;
48
+ do {
49
+ if (query === candidate) return true;
50
+ candidate = candidate[propName];
51
+ while (candidate && candidate.nodeType === candidate.TEXT_NODE && candidate.nodeValue === "") candidate = candidate[propName === "lastChild" ? "previousSibling" : "nextSibling"];
52
+ } while (candidate);
53
+ return false;
46
54
  }
47
- export {
48
- isEntirelySelected as default
49
- };
50
- //# sourceMappingURL=is-entirely-selected.mjs.map
55
+ export { isEntirelySelected as default };
56
+
57
+ //# sourceMappingURL=is-entirely-selected.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/is-entirely-selected.ts"],
4
- "sourcesContent": ["import { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\n\n/**\n * Zero width non-breaking space, used as padding in the editable DOM tree when\n * it is empty otherwise.\n */\nconst ZWNBSP = '\\ufeff';\n\n/**\n * Check whether the contents of the element have been entirely selected.\n * Returns true if there is no possibility of selection.\n *\n * @param element The element to check.\n *\n * @return True if entirely selected, false if not.\n */\nexport default function isEntirelySelected( element: HTMLElement ): boolean {\n\tif ( isInputOrTextArea( element ) ) {\n\t\treturn (\n\t\t\telement.selectionStart === 0 &&\n\t\t\telement.value.length === element.selectionEnd\n\t\t);\n\t}\n\n\tif ( ! element.isContentEditable ) {\n\t\treturn true;\n\t}\n\n\t// If the element is effectively empty (contains only the ZWNBSP\n\t// placeholder or nothing), consider it entirely selected since there's\n\t// nothing meaningful to select.\n\tconst text = element.textContent || '';\n\tif ( text === '' || text === ZWNBSP ) {\n\t\treturn true;\n\t}\n\n\tconst { ownerDocument } = element;\n\tconst { defaultView } = ownerDocument;\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tconst range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;\n\n\tif ( ! range ) {\n\t\treturn true;\n\t}\n\n\tconst { startContainer, endContainer, startOffset, endOffset } = range;\n\n\tif (\n\t\tstartContainer === element &&\n\t\tendContainer === element &&\n\t\tstartOffset === 0 &&\n\t\tendOffset === element.childNodes.length\n\t) {\n\t\treturn true;\n\t}\n\n\tconst lastChild = element.lastChild;\n\tassertIsDefined( lastChild, 'lastChild' );\n\tconst endContainerContentLength =\n\t\tendContainer.nodeType === endContainer.TEXT_NODE\n\t\t\t? ( endContainer as Text ).data.length\n\t\t\t: endContainer.childNodes.length;\n\n\treturn (\n\t\tisDeepChild( startContainer, element, 'firstChild' ) &&\n\t\tisDeepChild( endContainer, element, 'lastChild' ) &&\n\t\tstartOffset === 0 &&\n\t\tendOffset === endContainerContentLength\n\t);\n}\n\n/**\n * Check whether the contents of the element have been entirely selected.\n * Returns true if there is no possibility of selection.\n *\n * @param query The element to check.\n * @param container The container that we suspect \"query\" may be a first or last child of.\n * @param propName \"firstChild\" or \"lastChild\"\n *\n * @return True if query is a deep first/last child of container, false otherwise.\n */\nfunction isDeepChild(\n\tquery: HTMLElement | Node,\n\tcontainer: HTMLElement,\n\tpropName: 'firstChild' | 'lastChild'\n): boolean {\n\tlet candidate: HTMLElement | ChildNode | null = container;\n\tdo {\n\t\tif ( query === candidate ) {\n\t\t\treturn true;\n\t\t}\n\t\tcandidate = candidate[ propName ];\n\t\t// There may be empty text nodes between the first/last child, so ignore\n\t\t// them.\n\t\twhile (\n\t\t\tcandidate &&\n\t\t\tcandidate.nodeType === candidate.TEXT_NODE &&\n\t\t\tcandidate.nodeValue === ''\n\t\t) {\n\t\t\tcandidate =\n\t\t\t\tcandidate[\n\t\t\t\t\tpropName === 'lastChild' ? 'previousSibling' : 'nextSibling'\n\t\t\t\t];\n\t\t}\n\t} while ( candidate );\n\treturn false;\n}\n"],
5
- "mappings": ";AAAA,SAAS,uBAAuB;AAChC,OAAO,uBAAuB;AAM9B,IAAM,SAAS;AAUA,SAAR,mBAAqC,SAAgC;AAC3E,MAAK,kBAAmB,OAAQ,GAAI;AACnC,WACC,QAAQ,mBAAmB,KAC3B,QAAQ,MAAM,WAAW,QAAQ;AAAA,EAEnC;AAEA,MAAK,CAAE,QAAQ,mBAAoB;AAClC,WAAO;AAAA,EACR;AAKA,QAAM,OAAO,QAAQ,eAAe;AACpC,MAAK,SAAS,MAAM,SAAS,QAAS;AACrC,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,EAAE,YAAY,IAAI;AACxB,kBAAiB,aAAa,aAAc;AAC5C,QAAM,YAAY,YAAY,aAAa;AAC3C,kBAAiB,WAAW,WAAY;AACxC,QAAM,QAAQ,UAAU,aAAa,UAAU,WAAY,CAAE,IAAI;AAEjE,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,gBAAgB,cAAc,aAAa,UAAU,IAAI;AAEjE,MACC,mBAAmB,WACnB,iBAAiB,WACjB,gBAAgB,KAChB,cAAc,QAAQ,WAAW,QAChC;AACD,WAAO;AAAA,EACR;AAEA,QAAM,YAAY,QAAQ;AAC1B,kBAAiB,WAAW,WAAY;AACxC,QAAM,4BACL,aAAa,aAAa,aAAa,YAClC,aAAuB,KAAK,SAC9B,aAAa,WAAW;AAE5B,SACC,YAAa,gBAAgB,SAAS,YAAa,KACnD,YAAa,cAAc,SAAS,WAAY,KAChD,gBAAgB,KAChB,cAAc;AAEhB;AAYA,SAAS,YACR,OACA,WACA,UACU;AACV,MAAI,YAA4C;AAChD,KAAG;AACF,QAAK,UAAU,WAAY;AAC1B,aAAO;AAAA,IACR;AACA,gBAAY,UAAW,QAAS;AAGhC,WACC,aACA,UAAU,aAAa,UAAU,aACjC,UAAU,cAAc,IACvB;AACD,kBACC,UACC,aAAa,cAAc,oBAAoB,aAChD;AAAA,IACF;AAAA,EACD,SAAU;AACV,SAAO;AACR;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"is-entirely-selected.mjs","names":[],"sources":["../../src/dom/is-entirely-selected.ts"],"sourcesContent":["import { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\n\n/**\n * Zero width non-breaking space, used as padding in the editable DOM tree when\n * it is empty otherwise.\n */\nconst ZWNBSP = '\\ufeff';\n\n/**\n * Check whether the contents of the element have been entirely selected.\n * Returns true if there is no possibility of selection.\n *\n * @param element The element to check.\n *\n * @return True if entirely selected, false if not.\n */\nexport default function isEntirelySelected( element: HTMLElement ): boolean {\n\tif ( isInputOrTextArea( element ) ) {\n\t\treturn (\n\t\t\telement.selectionStart === 0 &&\n\t\t\telement.value.length === element.selectionEnd\n\t\t);\n\t}\n\n\tif ( ! element.isContentEditable ) {\n\t\treturn true;\n\t}\n\n\t// If the element is effectively empty (contains only the ZWNBSP\n\t// placeholder or nothing), consider it entirely selected since there's\n\t// nothing meaningful to select.\n\tconst text = element.textContent || '';\n\tif ( text === '' || text === ZWNBSP ) {\n\t\treturn true;\n\t}\n\n\tconst { ownerDocument } = element;\n\tconst { defaultView } = ownerDocument;\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tconst range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;\n\n\tif ( ! range ) {\n\t\treturn true;\n\t}\n\n\tconst { startContainer, endContainer, startOffset, endOffset } = range;\n\n\tif (\n\t\tstartContainer === element &&\n\t\tendContainer === element &&\n\t\tstartOffset === 0 &&\n\t\tendOffset === element.childNodes.length\n\t) {\n\t\treturn true;\n\t}\n\n\tconst lastChild = element.lastChild;\n\tassertIsDefined( lastChild, 'lastChild' );\n\tconst endContainerContentLength =\n\t\tendContainer.nodeType === endContainer.TEXT_NODE\n\t\t\t? ( endContainer as Text ).data.length\n\t\t\t: endContainer.childNodes.length;\n\n\treturn (\n\t\tisDeepChild( startContainer, element, 'firstChild' ) &&\n\t\tisDeepChild( endContainer, element, 'lastChild' ) &&\n\t\tstartOffset === 0 &&\n\t\tendOffset === endContainerContentLength\n\t);\n}\n\n/**\n * Check whether the contents of the element have been entirely selected.\n * Returns true if there is no possibility of selection.\n *\n * @param query The element to check.\n * @param container The container that we suspect \"query\" may be a first or last child of.\n * @param propName \"firstChild\" or \"lastChild\"\n *\n * @return True if query is a deep first/last child of container, false otherwise.\n */\nfunction isDeepChild(\n\tquery: HTMLElement | Node,\n\tcontainer: HTMLElement,\n\tpropName: 'firstChild' | 'lastChild'\n): boolean {\n\tlet candidate: HTMLElement | ChildNode | null = container;\n\tdo {\n\t\tif ( query === candidate ) {\n\t\t\treturn true;\n\t\t}\n\t\tcandidate = candidate[ propName ];\n\t\t// There may be empty text nodes between the first/last child, so ignore\n\t\t// them.\n\t\twhile (\n\t\t\tcandidate &&\n\t\t\tcandidate.nodeType === candidate.TEXT_NODE &&\n\t\t\tcandidate.nodeValue === ''\n\t\t) {\n\t\t\tcandidate =\n\t\t\t\tcandidate[\n\t\t\t\t\tpropName === 'lastChild' ? 'previousSibling' : 'nextSibling'\n\t\t\t\t];\n\t\t}\n\t} while ( candidate );\n\treturn false;\n}\n"],"mappings":";;;;;;;AAOA,MAAM,SAAS;;;;;;;;;AAUf,SAAwB,mBAAoB,SAAgC;CAC3E,IAAK,kBAAmB,OAAQ,GAC/B,OACC,QAAQ,mBAAmB,KAC3B,QAAQ,MAAM,WAAW,QAAQ;CAInC,IAAK,CAAE,QAAQ,mBACd,OAAO;CAMR,MAAM,OAAO,QAAQ,eAAe;CACpC,IAAK,SAAS,MAAM,SAAS,QAC5B,OAAO;CAGR,MAAM,EAAE,kBAAkB;CAC1B,MAAM,EAAE,gBAAgB;CACxB,gBAAiB,aAAa,aAAc;CAC5C,MAAM,YAAY,YAAY,aAAa;CAC3C,gBAAiB,WAAW,WAAY;CACxC,MAAM,QAAQ,UAAU,aAAa,UAAU,WAAY,CAAE,IAAI;CAEjE,IAAK,CAAE,OACN,OAAO;CAGR,MAAM,EAAE,gBAAgB,cAAc,aAAa,cAAc;CAEjE,IACC,mBAAmB,WACnB,iBAAiB,WACjB,gBAAgB,KAChB,cAAc,QAAQ,WAAW,QAEjC,OAAO;CAGR,MAAM,YAAY,QAAQ;CAC1B,gBAAiB,WAAW,WAAY;CACxC,MAAM,4BACL,aAAa,aAAa,aAAa,YAClC,aAAuB,KAAK,SAC9B,aAAa,WAAW;CAE5B,OACC,YAAa,gBAAgB,SAAS,YAAa,KACnD,YAAa,cAAc,SAAS,WAAY,KAChD,gBAAgB,KAChB,cAAc;AAEhB;;;;;;;;;;;AAYA,SAAS,YACR,OACA,WACA,UACU;CACV,IAAI,YAA4C;CAChD,GAAG;EACF,IAAK,UAAU,WACd,OAAO;EAER,YAAY,UAAW;EAGvB,OACC,aACA,UAAU,aAAa,UAAU,aACjC,UAAU,cAAc,IAExB,YACC,UACC,aAAa,cAAc,oBAAoB;CAGnD,SAAU;CACV,OAAO;AACR"}
@@ -1,14 +1,18 @@
1
- // packages/dom/src/dom/is-form-element.ts
2
1
  import isInputOrTextArea from "./is-input-or-text-area.mjs";
2
+ // packages/dom/src/dom/is-form-element.ts
3
+ /**
4
+ *
5
+ * Detects if element is a form element.
6
+ *
7
+ * @param element The element to check.
8
+ *
9
+ * @return True if form element and false otherwise.
10
+ */
3
11
  function isFormElement(element) {
4
- if (!element) {
5
- return false;
6
- }
7
- const { tagName } = element;
8
- const checkForInputTextarea = isInputOrTextArea(element);
9
- return checkForInputTextarea || tagName === "BUTTON" || tagName === "SELECT";
12
+ if (!element) return false;
13
+ const { tagName } = element;
14
+ return isInputOrTextArea(element) || tagName === "BUTTON" || tagName === "SELECT";
10
15
  }
11
- export {
12
- isFormElement as default
13
- };
14
- //# sourceMappingURL=is-form-element.mjs.map
16
+ export { isFormElement as default };
17
+
18
+ //# sourceMappingURL=is-form-element.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/is-form-element.ts"],
4
- "sourcesContent": ["import isInputOrTextArea from './is-input-or-text-area';\n\n/**\n *\n * Detects if element is a form element.\n *\n * @param element The element to check.\n *\n * @return True if form element and false otherwise.\n */\nexport default function isFormElement(\n\telement: Element | null | undefined\n): boolean {\n\tif ( ! element ) {\n\t\treturn false;\n\t}\n\n\tconst { tagName } = element;\n\tconst checkForInputTextarea = isInputOrTextArea( element );\n\treturn (\n\t\tcheckForInputTextarea || tagName === 'BUTTON' || tagName === 'SELECT'\n\t);\n}\n"],
5
- "mappings": ";AAAA,OAAO,uBAAuB;AAUf,SAAR,cACN,SACU;AACV,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,wBAAwB,kBAAmB,OAAQ;AACzD,SACC,yBAAyB,YAAY,YAAY,YAAY;AAE/D;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"is-form-element.mjs","names":[],"sources":["../../src/dom/is-form-element.ts"],"sourcesContent":["import isInputOrTextArea from './is-input-or-text-area';\n\n/**\n *\n * Detects if element is a form element.\n *\n * @param element The element to check.\n *\n * @return True if form element and false otherwise.\n */\nexport default function isFormElement(\n\telement: Element | null | undefined\n): boolean {\n\tif ( ! element ) {\n\t\treturn false;\n\t}\n\n\tconst { tagName } = element;\n\tconst checkForInputTextarea = isInputOrTextArea( element );\n\treturn (\n\t\tcheckForInputTextarea || tagName === 'BUTTON' || tagName === 'SELECT'\n\t);\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAwB,cACvB,SACU;CACV,IAAK,CAAE,SACN,OAAO;CAGR,MAAM,EAAE,YAAY;CAEpB,OAD8B,kBAAmB,OAE5B,KAAK,YAAY,YAAY,YAAY;AAE/D"}
@@ -1,9 +1,16 @@
1
- // packages/dom/src/dom/is-horizontal-edge.ts
2
1
  import isEdge from "./is-edge.mjs";
2
+ // packages/dom/src/dom/is-horizontal-edge.ts
3
+ /**
4
+ * Check whether the selection is horizontally at the edge of the container.
5
+ *
6
+ * @param {HTMLElement} container Focusable element.
7
+ * @param {boolean} isReverse Set to true to check left, false for right.
8
+ *
9
+ * @return {boolean} True if at the horizontal edge, false if not.
10
+ */
3
11
  function isHorizontalEdge(container, isReverse) {
4
- return isEdge(container, isReverse);
12
+ return isEdge(container, isReverse);
5
13
  }
6
- export {
7
- isHorizontalEdge as default
8
- };
9
- //# sourceMappingURL=is-horizontal-edge.mjs.map
14
+ export { isHorizontalEdge as default };
15
+
16
+ //# sourceMappingURL=is-horizontal-edge.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/is-horizontal-edge.ts"],
4
- "sourcesContent": ["import isEdge from './is-edge';\n\n/**\n * Check whether the selection is horizontally at the edge of the container.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse Set to true to check left, false for right.\n *\n * @return {boolean} True if at the horizontal edge, false if not.\n */\nexport default function isHorizontalEdge(\n\tcontainer: HTMLElement,\n\tisReverse: boolean\n): boolean {\n\treturn isEdge( container, isReverse );\n}\n"],
5
- "mappings": ";AAAA,OAAO,YAAY;AAUJ,SAAR,iBACN,WACA,WACU;AACV,SAAO,OAAQ,WAAW,SAAU;AACrC;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"is-horizontal-edge.mjs","names":[],"sources":["../../src/dom/is-horizontal-edge.ts"],"sourcesContent":["import isEdge from './is-edge';\n\n/**\n * Check whether the selection is horizontally at the edge of the container.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse Set to true to check left, false for right.\n *\n * @return {boolean} True if at the horizontal edge, false if not.\n */\nexport default function isHorizontalEdge(\n\tcontainer: HTMLElement,\n\tisReverse: boolean\n): boolean {\n\treturn isEdge( container, isReverse );\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAwB,iBACvB,WACA,WACU;CACV,OAAO,OAAQ,WAAW,SAAU;AACrC"}
@@ -1,8 +1,11 @@
1
1
  // packages/dom/src/dom/is-html-input-element.ts
2
+ /**
3
+ * @param {Node} node
4
+ * @return {node is HTMLInputElement} Whether the node is an HTMLInputElement.
5
+ */
2
6
  function isHTMLInputElement(node) {
3
- return node?.nodeName === "INPUT";
7
+ return node?.nodeName === "INPUT";
4
8
  }
5
- export {
6
- isHTMLInputElement as default
7
- };
8
- //# sourceMappingURL=is-html-input-element.mjs.map
9
+ export { isHTMLInputElement as default };
10
+
11
+ //# sourceMappingURL=is-html-input-element.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/is-html-input-element.ts"],
4
- "sourcesContent": ["/**\n * @param {Node} node\n * @return {node is HTMLInputElement} Whether the node is an HTMLInputElement.\n */\nexport default function isHTMLInputElement(\n\tnode: Node | null | undefined\n): node is HTMLInputElement {\n\treturn node?.nodeName === 'INPUT';\n}\n"],
5
- "mappings": ";AAIe,SAAR,mBACN,MAC2B;AAC3B,SAAO,MAAM,aAAa;AAC3B;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"is-html-input-element.mjs","names":[],"sources":["../../src/dom/is-html-input-element.ts"],"sourcesContent":["/**\n * @param {Node} node\n * @return {node is HTMLInputElement} Whether the node is an HTMLInputElement.\n */\nexport default function isHTMLInputElement(\n\tnode: Node | null | undefined\n): node is HTMLInputElement {\n\treturn node?.nodeName === 'INPUT';\n}\n"],"mappings":";;;;;AAIA,SAAwB,mBACvB,MAC2B;CAC3B,OAAO,MAAM,aAAa;AAC3B"}
@@ -1,8 +1,11 @@
1
1
  // packages/dom/src/dom/is-input-or-text-area.ts
2
+ /**
3
+ * @param {Element} element
4
+ * @return {element is HTMLInputElement | HTMLTextAreaElement} Whether the element is an input or textarea
5
+ */
2
6
  function isInputOrTextArea(element) {
3
- return element.tagName === "INPUT" || element.tagName === "TEXTAREA";
7
+ return element.tagName === "INPUT" || element.tagName === "TEXTAREA";
4
8
  }
5
- export {
6
- isInputOrTextArea as default
7
- };
8
- //# sourceMappingURL=is-input-or-text-area.mjs.map
9
+ export { isInputOrTextArea as default };
10
+
11
+ //# sourceMappingURL=is-input-or-text-area.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/is-input-or-text-area.ts"],
4
- "sourcesContent": ["/**\n * @param {Element} element\n * @return {element is HTMLInputElement | HTMLTextAreaElement} Whether the element is an input or textarea\n */\nexport default function isInputOrTextArea(\n\telement: Element\n): element is HTMLInputElement | HTMLTextAreaElement {\n\treturn element.tagName === 'INPUT' || element.tagName === 'TEXTAREA';\n}\n"],
5
- "mappings": ";AAIe,SAAR,kBACN,SACoD;AACpD,SAAO,QAAQ,YAAY,WAAW,QAAQ,YAAY;AAC3D;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"is-input-or-text-area.mjs","names":[],"sources":["../../src/dom/is-input-or-text-area.ts"],"sourcesContent":["/**\n * @param {Element} element\n * @return {element is HTMLInputElement | HTMLTextAreaElement} Whether the element is an input or textarea\n */\nexport default function isInputOrTextArea(\n\telement: Element\n): element is HTMLInputElement | HTMLTextAreaElement {\n\treturn element.tagName === 'INPUT' || element.tagName === 'TEXTAREA';\n}\n"],"mappings":";;;;;AAIA,SAAwB,kBACvB,SACoD;CACpD,OAAO,QAAQ,YAAY,WAAW,QAAQ,YAAY;AAC3D"}
@@ -1,14 +1,20 @@
1
- // packages/dom/src/dom/is-number-input.ts
2
1
  import deprecated from "@wordpress/deprecated";
3
2
  import isHTMLInputElement from "./is-html-input-element.mjs";
3
+ // packages/dom/src/dom/is-number-input.ts
4
+ /**
5
+ * Check whether the given element is an input field of type number.
6
+ *
7
+ * @param node The HTML node.
8
+ *
9
+ * @return True if the node is number input.
10
+ */
4
11
  function isNumberInput(node) {
5
- deprecated("wp.dom.isNumberInput", {
6
- since: "6.1",
7
- version: "6.5"
8
- });
9
- return isHTMLInputElement(node) && node.type === "number" && !isNaN(node.valueAsNumber);
12
+ deprecated("wp.dom.isNumberInput", {
13
+ since: "6.1",
14
+ version: "6.5"
15
+ });
16
+ return isHTMLInputElement(node) && node.type === "number" && !isNaN(node.valueAsNumber);
10
17
  }
11
- export {
12
- isNumberInput as default
13
- };
14
- //# sourceMappingURL=is-number-input.mjs.map
18
+ export { isNumberInput as default };
19
+
20
+ //# sourceMappingURL=is-number-input.mjs.map