@wordpress/dom 4.56.0 → 5.0.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 (327) hide show
  1. package/README.md +22 -22
  2. package/build/data-transfer.cjs +1 -1
  3. package/build/data-transfer.cjs.map +3 -3
  4. package/build/dom/caret-range-from-point.cjs +1 -1
  5. package/build/dom/caret-range-from-point.cjs.map +3 -3
  6. package/build/dom/clean-node-list.cjs +1 -1
  7. package/build/dom/clean-node-list.cjs.map +3 -3
  8. package/build/dom/compute-caret-rect.cjs +1 -1
  9. package/build/dom/compute-caret-rect.cjs.map +3 -3
  10. package/build/dom/document-has-selection.cjs +1 -1
  11. package/build/dom/document-has-selection.cjs.map +3 -3
  12. package/build/dom/document-has-text-selection.cjs +1 -1
  13. package/build/dom/document-has-text-selection.cjs.map +3 -3
  14. package/build/dom/document-has-uncollapsed-selection.cjs +1 -1
  15. package/build/dom/document-has-uncollapsed-selection.cjs.map +3 -3
  16. package/build/dom/get-computed-style.cjs +1 -1
  17. package/build/dom/get-computed-style.cjs.map +3 -3
  18. package/build/dom/get-offset-parent.cjs +7 -15
  19. package/build/dom/get-offset-parent.cjs.map +4 -4
  20. package/build/dom/get-range-height.cjs +1 -1
  21. package/build/dom/get-range-height.cjs.map +3 -3
  22. package/build/dom/get-rectangle-from-range.cjs +3 -8
  23. package/build/dom/get-rectangle-from-range.cjs.map +3 -3
  24. package/build/dom/get-scroll-container.cjs +2 -6
  25. package/build/dom/get-scroll-container.cjs.map +3 -3
  26. package/build/dom/hidden-caret-range-from-point.cjs +1 -1
  27. package/build/dom/hidden-caret-range-from-point.cjs.map +3 -3
  28. package/build/dom/index.cjs +1 -1
  29. package/build/dom/index.cjs.map +1 -1
  30. package/build/dom/input-field-has-uncollapsed-selection.cjs +2 -5
  31. package/build/dom/input-field-has-uncollapsed-selection.cjs.map +3 -3
  32. package/build/dom/insert-after.cjs +1 -1
  33. package/build/dom/insert-after.cjs.map +3 -3
  34. package/build/dom/is-edge.cjs +1 -1
  35. package/build/dom/is-edge.cjs.map +3 -3
  36. package/build/dom/is-element.cjs +1 -1
  37. package/build/dom/is-element.cjs.map +3 -3
  38. package/build/dom/is-empty.cjs +2 -5
  39. package/build/dom/is-empty.cjs.map +3 -3
  40. package/build/dom/is-entirely-selected.cjs +2 -5
  41. package/build/dom/is-entirely-selected.cjs.map +3 -3
  42. package/build/dom/is-form-element.cjs +1 -1
  43. package/build/dom/is-form-element.cjs.map +3 -3
  44. package/build/dom/is-horizontal-edge.cjs +1 -1
  45. package/build/dom/is-horizontal-edge.cjs.map +3 -3
  46. package/build/dom/is-html-input-element.cjs +1 -1
  47. package/build/dom/is-html-input-element.cjs.map +3 -3
  48. package/build/dom/is-input-or-text-area.cjs +1 -1
  49. package/build/dom/is-input-or-text-area.cjs.map +3 -3
  50. package/build/dom/is-number-input.cjs +1 -1
  51. package/build/dom/is-number-input.cjs.map +3 -3
  52. package/build/dom/is-rtl.cjs +1 -1
  53. package/build/dom/is-rtl.cjs.map +3 -3
  54. package/build/dom/is-selection-forward.cjs +1 -1
  55. package/build/dom/is-selection-forward.cjs.map +3 -3
  56. package/build/dom/is-text-field.cjs +2 -3
  57. package/build/dom/is-text-field.cjs.map +3 -3
  58. package/build/dom/is-vertical-edge.cjs +1 -1
  59. package/build/dom/is-vertical-edge.cjs.map +3 -3
  60. package/build/dom/place-caret-at-edge.cjs +1 -1
  61. package/build/dom/place-caret-at-edge.cjs.map +3 -3
  62. package/build/dom/place-caret-at-horizontal-edge.cjs +1 -1
  63. package/build/dom/place-caret-at-horizontal-edge.cjs.map +3 -3
  64. package/build/dom/place-caret-at-vertical-edge.cjs +1 -1
  65. package/build/dom/place-caret-at-vertical-edge.cjs.map +3 -3
  66. package/build/dom/remove-invalid-html.cjs +1 -1
  67. package/build/dom/remove-invalid-html.cjs.map +3 -3
  68. package/build/dom/remove.cjs +1 -1
  69. package/build/dom/remove.cjs.map +3 -3
  70. package/build/dom/replace-tag.cjs +1 -1
  71. package/build/dom/replace-tag.cjs.map +3 -3
  72. package/build/dom/replace.cjs +1 -1
  73. package/build/dom/replace.cjs.map +3 -3
  74. package/build/dom/safe-html.cjs +1 -1
  75. package/build/dom/safe-html.cjs.map +3 -3
  76. package/build/dom/scroll-if-no-range.cjs +1 -1
  77. package/build/dom/scroll-if-no-range.cjs.map +3 -3
  78. package/build/dom/strip-html.cjs +1 -1
  79. package/build/dom/strip-html.cjs.map +3 -3
  80. package/build/dom/types.cjs +19 -0
  81. package/build/dom/types.cjs.map +7 -0
  82. package/build/dom/unwrap.cjs +1 -1
  83. package/build/dom/unwrap.cjs.map +3 -3
  84. package/build/dom/wrap.cjs +1 -1
  85. package/build/dom/wrap.cjs.map +3 -3
  86. package/build/focusable.cjs +5 -6
  87. package/build/focusable.cjs.map +3 -3
  88. package/build/index.cjs +1 -1
  89. package/build/index.cjs.map +2 -2
  90. package/build/phrasing-content.cjs +1 -1
  91. package/build/phrasing-content.cjs.map +3 -3
  92. package/build/tabbable.cjs +1 -1
  93. package/build/tabbable.cjs.map +3 -3
  94. package/build/types.cjs +19 -0
  95. package/build/types.cjs.map +7 -0
  96. package/build-module/data-transfer.mjs +1 -1
  97. package/build-module/data-transfer.mjs.map +3 -3
  98. package/build-module/dom/caret-range-from-point.mjs +1 -1
  99. package/build-module/dom/caret-range-from-point.mjs.map +3 -3
  100. package/build-module/dom/clean-node-list.mjs +1 -1
  101. package/build-module/dom/clean-node-list.mjs.map +3 -3
  102. package/build-module/dom/compute-caret-rect.mjs +1 -1
  103. package/build-module/dom/compute-caret-rect.mjs.map +3 -3
  104. package/build-module/dom/document-has-selection.mjs +1 -1
  105. package/build-module/dom/document-has-selection.mjs.map +3 -3
  106. package/build-module/dom/document-has-text-selection.mjs +1 -1
  107. package/build-module/dom/document-has-text-selection.mjs.map +3 -3
  108. package/build-module/dom/document-has-uncollapsed-selection.mjs +1 -1
  109. package/build-module/dom/document-has-uncollapsed-selection.mjs.map +3 -3
  110. package/build-module/dom/get-computed-style.mjs +1 -1
  111. package/build-module/dom/get-computed-style.mjs.map +3 -3
  112. package/build-module/dom/get-offset-parent.mjs +7 -15
  113. package/build-module/dom/get-offset-parent.mjs.map +3 -3
  114. package/build-module/dom/get-range-height.mjs +1 -1
  115. package/build-module/dom/get-range-height.mjs.map +3 -3
  116. package/build-module/dom/get-rectangle-from-range.mjs +3 -8
  117. package/build-module/dom/get-rectangle-from-range.mjs.map +3 -3
  118. package/build-module/dom/get-scroll-container.mjs +2 -6
  119. package/build-module/dom/get-scroll-container.mjs.map +3 -3
  120. package/build-module/dom/hidden-caret-range-from-point.mjs +1 -1
  121. package/build-module/dom/hidden-caret-range-from-point.mjs.map +3 -3
  122. package/build-module/dom/index.mjs +1 -1
  123. package/build-module/dom/index.mjs.map +1 -1
  124. package/build-module/dom/input-field-has-uncollapsed-selection.mjs +2 -5
  125. package/build-module/dom/input-field-has-uncollapsed-selection.mjs.map +3 -3
  126. package/build-module/dom/insert-after.mjs +1 -1
  127. package/build-module/dom/insert-after.mjs.map +3 -3
  128. package/build-module/dom/is-edge.mjs +1 -1
  129. package/build-module/dom/is-edge.mjs.map +3 -3
  130. package/build-module/dom/is-element.mjs +1 -1
  131. package/build-module/dom/is-element.mjs.map +3 -3
  132. package/build-module/dom/is-empty.mjs +2 -5
  133. package/build-module/dom/is-empty.mjs.map +3 -3
  134. package/build-module/dom/is-entirely-selected.mjs +2 -5
  135. package/build-module/dom/is-entirely-selected.mjs.map +3 -3
  136. package/build-module/dom/is-form-element.mjs +1 -1
  137. package/build-module/dom/is-form-element.mjs.map +3 -3
  138. package/build-module/dom/is-horizontal-edge.mjs +1 -1
  139. package/build-module/dom/is-horizontal-edge.mjs.map +3 -3
  140. package/build-module/dom/is-html-input-element.mjs +1 -1
  141. package/build-module/dom/is-html-input-element.mjs.map +3 -3
  142. package/build-module/dom/is-input-or-text-area.mjs +1 -1
  143. package/build-module/dom/is-input-or-text-area.mjs.map +3 -3
  144. package/build-module/dom/is-number-input.mjs +1 -1
  145. package/build-module/dom/is-number-input.mjs.map +3 -3
  146. package/build-module/dom/is-rtl.mjs +1 -1
  147. package/build-module/dom/is-rtl.mjs.map +3 -3
  148. package/build-module/dom/is-selection-forward.mjs +1 -1
  149. package/build-module/dom/is-selection-forward.mjs.map +3 -3
  150. package/build-module/dom/is-text-field.mjs +2 -3
  151. package/build-module/dom/is-text-field.mjs.map +3 -3
  152. package/build-module/dom/is-vertical-edge.mjs +1 -1
  153. package/build-module/dom/is-vertical-edge.mjs.map +3 -3
  154. package/build-module/dom/place-caret-at-edge.mjs +1 -1
  155. package/build-module/dom/place-caret-at-edge.mjs.map +3 -3
  156. package/build-module/dom/place-caret-at-horizontal-edge.mjs +1 -1
  157. package/build-module/dom/place-caret-at-horizontal-edge.mjs.map +3 -3
  158. package/build-module/dom/place-caret-at-vertical-edge.mjs +1 -1
  159. package/build-module/dom/place-caret-at-vertical-edge.mjs.map +3 -3
  160. package/build-module/dom/remove-invalid-html.mjs +1 -1
  161. package/build-module/dom/remove-invalid-html.mjs.map +3 -3
  162. package/build-module/dom/remove.mjs +1 -1
  163. package/build-module/dom/remove.mjs.map +3 -3
  164. package/build-module/dom/replace-tag.mjs +1 -1
  165. package/build-module/dom/replace-tag.mjs.map +3 -3
  166. package/build-module/dom/replace.mjs +1 -1
  167. package/build-module/dom/replace.mjs.map +3 -3
  168. package/build-module/dom/safe-html.mjs +1 -1
  169. package/build-module/dom/safe-html.mjs.map +3 -3
  170. package/build-module/dom/scroll-if-no-range.mjs +1 -1
  171. package/build-module/dom/scroll-if-no-range.mjs.map +3 -3
  172. package/build-module/dom/strip-html.mjs +1 -1
  173. package/build-module/dom/strip-html.mjs.map +3 -3
  174. package/build-module/dom/types.mjs +1 -0
  175. package/build-module/dom/types.mjs.map +7 -0
  176. package/build-module/dom/unwrap.mjs +1 -1
  177. package/build-module/dom/unwrap.mjs.map +3 -3
  178. package/build-module/dom/wrap.mjs +1 -1
  179. package/build-module/dom/wrap.mjs.map +3 -3
  180. package/build-module/focusable.mjs +5 -6
  181. package/build-module/focusable.mjs.map +3 -3
  182. package/build-module/index.mjs +1 -1
  183. package/build-module/index.mjs.map +2 -2
  184. package/build-module/phrasing-content.mjs +1 -1
  185. package/build-module/phrasing-content.mjs.map +3 -3
  186. package/build-module/tabbable.mjs +1 -1
  187. package/build-module/tabbable.mjs.map +3 -3
  188. package/build-module/types.mjs +1 -0
  189. package/build-module/types.mjs.map +7 -0
  190. package/build-types/data-transfer.d.ts +2 -2
  191. package/build-types/data-transfer.d.ts.map +1 -1
  192. package/build-types/dom/caret-range-from-point.d.ts +4 -4
  193. package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
  194. package/build-types/dom/clean-node-list.d.ts +5 -45
  195. package/build-types/dom/clean-node-list.d.ts.map +1 -1
  196. package/build-types/dom/compute-caret-rect.d.ts +2 -2
  197. package/build-types/dom/compute-caret-rect.d.ts.map +1 -1
  198. package/build-types/dom/document-has-selection.d.ts +2 -2
  199. package/build-types/dom/document-has-selection.d.ts.map +1 -1
  200. package/build-types/dom/document-has-text-selection.d.ts +2 -2
  201. package/build-types/dom/document-has-text-selection.d.ts.map +1 -1
  202. package/build-types/dom/document-has-uncollapsed-selection.d.ts +2 -2
  203. package/build-types/dom/document-has-uncollapsed-selection.d.ts.map +1 -1
  204. package/build-types/dom/get-computed-style.d.ts +3 -3
  205. package/build-types/dom/get-computed-style.d.ts.map +1 -1
  206. package/build-types/dom/get-offset-parent.d.ts +2 -2
  207. package/build-types/dom/get-offset-parent.d.ts.map +1 -1
  208. package/build-types/dom/get-range-height.d.ts +2 -2
  209. package/build-types/dom/get-range-height.d.ts.map +1 -1
  210. package/build-types/dom/get-rectangle-from-range.d.ts +2 -2
  211. package/build-types/dom/get-rectangle-from-range.d.ts.map +1 -1
  212. package/build-types/dom/get-scroll-container.d.ts +5 -5
  213. package/build-types/dom/get-scroll-container.d.ts.map +1 -1
  214. package/build-types/dom/hidden-caret-range-from-point.d.ts +5 -5
  215. package/build-types/dom/hidden-caret-range-from-point.d.ts.map +1 -1
  216. package/build-types/dom/index.d.ts.map +1 -1
  217. package/build-types/dom/input-field-has-uncollapsed-selection.d.ts +2 -2
  218. package/build-types/dom/input-field-has-uncollapsed-selection.d.ts.map +1 -1
  219. package/build-types/dom/insert-after.d.ts +2 -3
  220. package/build-types/dom/insert-after.d.ts.map +1 -1
  221. package/build-types/dom/is-edge.d.ts +4 -4
  222. package/build-types/dom/is-edge.d.ts.map +1 -1
  223. package/build-types/dom/is-element.d.ts.map +1 -1
  224. package/build-types/dom/is-empty.d.ts +3 -3
  225. package/build-types/dom/is-empty.d.ts.map +1 -1
  226. package/build-types/dom/is-entirely-selected.d.ts +2 -2
  227. package/build-types/dom/is-entirely-selected.d.ts.map +1 -1
  228. package/build-types/dom/is-form-element.d.ts +3 -3
  229. package/build-types/dom/is-form-element.d.ts.map +1 -1
  230. package/build-types/dom/is-horizontal-edge.d.ts.map +1 -1
  231. package/build-types/dom/is-html-input-element.d.ts +1 -1
  232. package/build-types/dom/is-html-input-element.d.ts.map +1 -1
  233. package/build-types/dom/is-input-or-text-area.d.ts.map +1 -1
  234. package/build-types/dom/is-number-input.d.ts +2 -2
  235. package/build-types/dom/is-number-input.d.ts.map +1 -1
  236. package/build-types/dom/is-rtl.d.ts +2 -2
  237. package/build-types/dom/is-rtl.d.ts.map +1 -1
  238. package/build-types/dom/is-selection-forward.d.ts +2 -2
  239. package/build-types/dom/is-selection-forward.d.ts.map +1 -1
  240. package/build-types/dom/is-text-field.d.ts +2 -2
  241. package/build-types/dom/is-text-field.d.ts.map +1 -1
  242. package/build-types/dom/is-vertical-edge.d.ts.map +1 -1
  243. package/build-types/dom/place-caret-at-edge.d.ts +3 -3
  244. package/build-types/dom/place-caret-at-edge.d.ts.map +1 -1
  245. package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
  246. package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
  247. package/build-types/dom/remove-invalid-html.d.ts +5 -4
  248. package/build-types/dom/remove-invalid-html.d.ts.map +1 -1
  249. package/build-types/dom/remove.d.ts +1 -2
  250. package/build-types/dom/remove.d.ts.map +1 -1
  251. package/build-types/dom/replace-tag.d.ts +3 -3
  252. package/build-types/dom/replace-tag.d.ts.map +1 -1
  253. package/build-types/dom/replace.d.ts +2 -3
  254. package/build-types/dom/replace.d.ts.map +1 -1
  255. package/build-types/dom/safe-html.d.ts +2 -2
  256. package/build-types/dom/safe-html.d.ts.map +1 -1
  257. package/build-types/dom/scroll-if-no-range.d.ts +5 -5
  258. package/build-types/dom/scroll-if-no-range.d.ts.map +1 -1
  259. package/build-types/dom/strip-html.d.ts +2 -2
  260. package/build-types/dom/strip-html.d.ts.map +1 -1
  261. package/build-types/dom/types.d.ts +32 -0
  262. package/build-types/dom/types.d.ts.map +1 -0
  263. package/build-types/dom/unwrap.d.ts +1 -3
  264. package/build-types/dom/unwrap.d.ts.map +1 -1
  265. package/build-types/dom/wrap.d.ts +2 -2
  266. package/build-types/dom/wrap.d.ts.map +1 -1
  267. package/build-types/focusable.d.ts +11 -30
  268. package/build-types/focusable.d.ts.map +1 -1
  269. package/build-types/index.d.ts +17 -0
  270. package/build-types/index.d.ts.map +1 -1
  271. package/build-types/phrasing-content.d.ts +9 -24
  272. package/build-types/phrasing-content.d.ts.map +1 -1
  273. package/build-types/tabbable.d.ts +10 -15
  274. package/build-types/tabbable.d.ts.map +1 -1
  275. package/build-types/types.d.ts +29 -0
  276. package/build-types/types.d.ts.map +1 -0
  277. package/package.json +6 -7
  278. package/src/{data-transfer.js → data-transfer.ts} +3 -3
  279. package/src/dom/{caret-range-from-point.js → caret-range-from-point.ts} +9 -5
  280. package/src/dom/{clean-node-list.js → clean-node-list.ts} +16 -24
  281. package/src/dom/{compute-caret-rect.js → compute-caret-rect.ts} +3 -3
  282. package/src/dom/{document-has-selection.js → document-has-selection.ts} +3 -3
  283. package/src/dom/{document-has-text-selection.js → document-has-text-selection.ts} +3 -3
  284. package/src/dom/{document-has-uncollapsed-selection.js → document-has-uncollapsed-selection.ts} +5 -3
  285. package/src/dom/{get-computed-style.js → get-computed-style.ts} +5 -3
  286. package/src/dom/{get-offset-parent.js → get-offset-parent.ts} +9 -14
  287. package/src/dom/{get-range-height.js → get-range-height.ts} +3 -3
  288. package/src/dom/{get-rectangle-from-range.js → get-rectangle-from-range.ts} +6 -12
  289. package/src/dom/{get-scroll-container.js → get-scroll-container.ts} +9 -9
  290. package/src/dom/{hidden-caret-range-from-point.js → hidden-caret-range-from-point.ts} +11 -6
  291. package/src/dom/{input-field-has-uncollapsed-selection.js → input-field-has-uncollapsed-selection.ts} +7 -5
  292. package/src/dom/{insert-after.js → insert-after.ts} +6 -4
  293. package/src/dom/{is-edge.js → is-edge.ts} +9 -5
  294. package/src/dom/{is-element.js → is-element.ts} +3 -1
  295. package/src/dom/{is-empty.js → is-empty.ts} +5 -7
  296. package/src/dom/{is-entirely-selected.js → is-entirely-selected.ts} +14 -11
  297. package/src/dom/{is-form-element.js → is-form-element.ts} +5 -3
  298. package/src/dom/{is-horizontal-edge.js → is-horizontal-edge.ts} +4 -1
  299. package/src/dom/{is-html-input-element.js → is-html-input-element.ts} +3 -1
  300. package/src/dom/{is-input-or-text-area.js → is-input-or-text-area.ts} +3 -1
  301. package/src/dom/{is-number-input.js → is-number-input.ts} +3 -3
  302. package/src/dom/{is-rtl.js → is-rtl.ts} +3 -3
  303. package/src/dom/{is-selection-forward.js → is-selection-forward.ts} +3 -3
  304. package/src/dom/{is-text-field.js → is-text-field.ts} +4 -4
  305. package/src/dom/{is-vertical-edge.js → is-vertical-edge.ts} +4 -1
  306. package/src/dom/{place-caret-at-edge.js → place-caret-at-edge.ts} +17 -9
  307. package/src/dom/{place-caret-at-horizontal-edge.js → place-caret-at-horizontal-edge.ts} +4 -1
  308. package/src/dom/{place-caret-at-vertical-edge.js → place-caret-at-vertical-edge.ts} +5 -1
  309. package/src/dom/{remove-invalid-html.js → remove-invalid-html.ts} +9 -4
  310. package/src/dom/{remove.js → remove.ts} +2 -3
  311. package/src/dom/{replace-tag.js → replace-tag.ts} +4 -4
  312. package/src/dom/{replace.js → replace.ts} +6 -4
  313. package/src/dom/{safe-html.js → safe-html.ts} +3 -3
  314. package/src/dom/{scroll-if-no-range.js → scroll-if-no-range.ts} +9 -5
  315. package/src/dom/{strip-html.js → strip-html.ts} +3 -3
  316. package/src/dom/types.ts +28 -0
  317. package/src/dom/{unwrap.js → unwrap.ts} +2 -4
  318. package/src/dom/{wrap.js → wrap.ts} +3 -3
  319. package/src/{focusable.js → focusable.ts} +34 -32
  320. package/src/index.ts +33 -0
  321. package/src/{phrasing-content.js → phrasing-content.ts} +15 -30
  322. package/src/{tabbable.js → tabbable.ts} +48 -39
  323. package/src/test/dom.jsdom.test.js +21 -0
  324. package/src/types.ts +32 -0
  325. package/CHANGELOG.md +0 -315
  326. package/src/index.js +0 -12
  327. /package/src/dom/{index.js → index.ts} +0 -0
@@ -0,0 +1,29 @@
1
+ export interface SemanticElementDefinition {
2
+ /**
3
+ * Content attributes
4
+ */
5
+ attributes?: string[];
6
+ /**
7
+ * Allowed child elements, or `'*'` for any
8
+ */
9
+ children?: ContentSchema | '*';
10
+ }
11
+ export type ContentSchema = Record<string, SemanticElementDefinition>;
12
+ export interface FindFocusableOptions {
13
+ /**
14
+ * If set, only return elements that are sequentially focusable.
15
+ * Non-interactive elements with a negative `tabindex` are focusable but
16
+ * not sequentially focusable.
17
+ */
18
+ sequential?: boolean;
19
+ }
20
+ export type MaybeHTMLInputElement = HTMLElement & {
21
+ type?: string;
22
+ checked?: boolean;
23
+ name?: string;
24
+ };
25
+ export interface ObjectTabbable {
26
+ element: HTMLElement;
27
+ index: number;
28
+ }
29
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,aAAa,GAAG,GAAG,CAAC;CAC/B;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,CAAE,MAAM,EAAE,yBAAyB,CAAE,CAAC;AAExE,MAAM,WAAW,oBAAoB;IACpC;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,MAAM,qBAAqB,GAAG,WAAW,GAAG;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dom",
3
- "version": "4.56.0",
3
+ "version": "5.0.0",
4
4
  "description": "DOM utilities module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -20,14 +20,13 @@
20
20
  "url": "https://github.com/WordPress/gutenberg/issues"
21
21
  },
22
22
  "engines": {
23
- "node": ">=18.12.0"
23
+ "node": ">=22.13.0"
24
24
  },
25
25
  "files": [
26
26
  "src",
27
27
  "build",
28
28
  "build-module",
29
- "build-types",
30
- "*.md"
29
+ "build-types"
31
30
  ],
32
31
  "main": "build/index.cjs",
33
32
  "module": "build-module/index.mjs",
@@ -43,13 +42,13 @@
43
42
  "types": "build-types",
44
43
  "sideEffects": false,
45
44
  "dependencies": {
46
- "@wordpress/deprecated": "^4.56.0"
45
+ "@wordpress/deprecated": "^5.0.0"
47
46
  },
48
47
  "devDependencies": {
49
- "vitest": "^5.0.0"
48
+ "vitest": "^5.0.3"
50
49
  },
51
50
  "publishConfig": {
52
51
  "access": "public"
53
52
  },
54
- "gitHead": "56d8058eda6e30c4cc8bfc37818fa6ed972f7dc2"
53
+ "gitHead": "8d30f92cbbde3ddf781c8799443c649befbbcb88"
55
54
  }
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Gets all files from a DataTransfer object.
3
3
  *
4
- * @param {DataTransfer} dataTransfer DataTransfer object to inspect.
4
+ * @param dataTransfer DataTransfer object to inspect.
5
5
  *
6
- * @return {File[]} An array containing all files.
6
+ * @return An array containing all files.
7
7
  */
8
- export function getFilesFromDataTransfer( dataTransfer ) {
8
+ export function getFilesFromDataTransfer( dataTransfer: DataTransfer ): File[] {
9
9
  const files = Array.from( dataTransfer.files );
10
10
 
11
11
  Array.from( dataTransfer.items ).forEach( ( item ) => {
@@ -6,13 +6,17 @@
6
6
  *
7
7
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint
8
8
  *
9
- * @param {Document} doc The document of the range.
10
- * @param {number} x Horizontal position within the current viewport.
11
- * @param {number} y Vertical position within the current viewport.
9
+ * @param doc The document of the range.
10
+ * @param x Horizontal position within the current viewport.
11
+ * @param y Vertical position within the current viewport.
12
12
  *
13
- * @return {Range | null} The best range for the given point.
13
+ * @return The best range for the given point.
14
14
  */
15
- export default function caretRangeFromPoint( doc, x, y ) {
15
+ export default function caretRangeFromPoint(
16
+ doc: Document,
17
+ x: number,
18
+ y: number
19
+ ): Range | null {
16
20
  if ( doc.caretPositionFromPoint ) {
17
21
  const point = doc.caretPositionFromPoint( x, y );
18
22
 
@@ -4,33 +4,27 @@ import unwrap from './unwrap';
4
4
  import { isPhrasingContent } from '../phrasing-content';
5
5
  import insertAfter from './insert-after';
6
6
  import isElement from './is-element';
7
+ import type { Schema } from './types';
7
8
 
8
9
  const noop = () => {};
9
10
 
10
- /**
11
- * @typedef SchemaItem
12
- * @property {string[]} [attributes] Attributes.
13
- * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against. Use '*' to keep all classes.
14
- * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.
15
- * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.
16
- * @property {boolean} allowEmpty Whether to allow nodes without children.
17
- * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.
18
- */
19
-
20
- /** @typedef {{ [tag: string]: SchemaItem }} Schema */
21
-
22
11
  /**
23
12
  * Given a schema, unwraps or removes nodes, attributes and classes on a node
24
13
  * list.
25
14
  *
26
- * @param {NodeList} nodeList The nodeList to filter.
27
- * @param {Document} doc The document of the nodeList.
28
- * @param {Schema} schema An array of functions that can mutate with the provided node.
29
- * @param {boolean} inline Whether to clean for inline mode.
15
+ * @param nodeList The nodeList to filter.
16
+ * @param doc The document of the nodeList.
17
+ * @param schema Schema for the HTML.
18
+ * @param inline Whether to clean for inline mode.
30
19
  */
31
- export default function cleanNodeList( nodeList, doc, schema, inline ) {
20
+ export default function cleanNodeList(
21
+ nodeList: NodeList,
22
+ doc: Document,
23
+ schema: Schema,
24
+ inline: boolean
25
+ ) {
32
26
  Array.from( nodeList ).forEach(
33
- ( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {
27
+ ( node: Node & { nextElementSibling?: unknown } ) => {
34
28
  const tag = node.nodeName.toLowerCase();
35
29
 
36
30
  // It's a valid child, if the tag exists in the schema without an isMatch
@@ -84,13 +78,11 @@ export default function cleanNodeList( nodeList, doc, schema, inline ) {
84
78
  // Keep all classes.
85
79
  return () => true;
86
80
  } else if ( typeof item === 'string' ) {
87
- return (
88
- /** @type {string} */ className
89
- ) => className === item;
81
+ return ( className: string ) =>
82
+ className === item;
90
83
  } else if ( item instanceof RegExp ) {
91
- return (
92
- /** @type {string} */ className
93
- ) => item.test( className );
84
+ return ( className: string ) =>
85
+ item.test( className );
94
86
  }
95
87
 
96
88
  return noop;
@@ -4,11 +4,11 @@ import { assertIsDefined } from '../utils/assert-is-defined';
4
4
  /**
5
5
  * Get the rectangle for the selection in a container.
6
6
  *
7
- * @param {Window} win The window of the selection.
7
+ * @param win The window of the selection.
8
8
  *
9
- * @return {DOMRect | null} The rectangle.
9
+ * @return The rectangle.
10
10
  */
11
- export default function computeCaretRect( win ) {
11
+ export default function computeCaretRect( win: Window ): DOMRect | null {
12
12
  const selection = win.getSelection();
13
13
  assertIsDefined( selection, 'selection' );
14
14
  const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;
@@ -6,11 +6,11 @@ import documentHasTextSelection from './document-has-text-selection';
6
6
  * Check whether the current document has a selection. This includes focus in
7
7
  * input fields, textareas, and general rich-text selection.
8
8
  *
9
- * @param {Document} doc The document to check.
9
+ * @param doc The document to check.
10
10
  *
11
- * @return {boolean} True if there is selection, false if not.
11
+ * @return True if there is selection, false if not.
12
12
  */
13
- export default function documentHasSelection( doc ) {
13
+ export default function documentHasSelection( doc: Document ): boolean {
14
14
  return (
15
15
  !! doc.activeElement &&
16
16
  ( isHTMLInputElement( doc.activeElement ) ||
@@ -7,11 +7,11 @@ import { assertIsDefined } from '../utils/assert-is-defined';
7
7
  *
8
8
  * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
9
9
  *
10
- * @param {Document} doc The document to check.
10
+ * @param doc The document to check.
11
11
  *
12
- * @return {boolean} True if there is selection, false if not.
12
+ * @return True if there is selection, false if not.
13
13
  */
14
- export default function documentHasTextSelection( doc ) {
14
+ export default function documentHasTextSelection( doc: Document ): boolean {
15
15
  assertIsDefined( doc.defaultView, 'doc.defaultView' );
16
16
  const selection = doc.defaultView.getSelection();
17
17
  assertIsDefined( selection, 'selection' );
@@ -6,11 +6,13 @@ import inputFieldHasUncollapsedSelection from './input-field-has-uncollapsed-sel
6
6
  * This includes ranges of text across elements and any selection inside
7
7
  * textual `<input>` and `<textarea>` elements.
8
8
  *
9
- * @param {Document} doc The document to check.
9
+ * @param doc The document to check.
10
10
  *
11
- * @return {boolean} Whether there is any recognizable text selection in the document.
11
+ * @return Whether there is any recognizable text selection in the document.
12
12
  */
13
- export default function documentHasUncollapsedSelection( doc ) {
13
+ export default function documentHasUncollapsedSelection(
14
+ doc: Document
15
+ ): boolean {
14
16
  return (
15
17
  documentHasTextSelection( doc ) ||
16
18
  ( !! doc.activeElement &&
@@ -1,10 +1,12 @@
1
1
  import { assertIsDefined } from '../utils/assert-is-defined';
2
2
 
3
3
  /**
4
- * @param {Element} element
5
- * @return {ReturnType<Window['getComputedStyle']>} The computed style for the element.
4
+ * @param element
5
+ * @return The computed style for the element.
6
6
  */
7
- export default function getComputedStyle( element ) {
7
+ export default function getComputedStyle(
8
+ element: Element
9
+ ): CSSStyleDeclaration {
8
10
  assertIsDefined(
9
11
  element.ownerDocument.defaultView,
10
12
  'element.ownerDocument.defaultView'
@@ -1,4 +1,5 @@
1
1
  import getComputedStyle from './get-computed-style';
2
+ import isElement from './is-element';
2
3
 
3
4
  /**
4
5
  * Returns the closest positioned element, or null under any of the conditions
@@ -7,18 +8,16 @@ import getComputedStyle from './get-computed-style';
7
8
  *
8
9
  * @see https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent
9
10
  *
10
- * @param {Node} node Node from which to find offset parent.
11
+ * @param node Node from which to find offset parent.
11
12
  *
12
- * @return {Node | null} Offset parent.
13
+ * @return Offset parent.
13
14
  */
14
- export default function getOffsetParent( node ) {
15
+ export default function getOffsetParent( node: Node ): Node | null {
15
16
  // Cannot retrieve computed style or offset parent only anything other than
16
17
  // an element node, so find the closest element node.
17
- let closestElement;
18
- while ( ( closestElement = /** @type {Node} */ ( node.parentNode ) ) ) {
19
- if ( closestElement.nodeType === closestElement.ELEMENT_NODE ) {
20
- break;
21
- }
18
+ let closestElement = node.parentNode;
19
+ while ( closestElement && ! isElement( closestElement ) ) {
20
+ closestElement = closestElement.parentNode;
22
21
  }
23
22
 
24
23
  if ( ! closestElement ) {
@@ -27,14 +26,10 @@ export default function getOffsetParent( node ) {
27
26
 
28
27
  // If the closest element is already positioned, return it, as offsetParent
29
28
  // does not otherwise consider the node itself.
30
- if (
31
- getComputedStyle( /** @type {Element} */ ( closestElement ) )
32
- .position !== 'static'
33
- ) {
29
+ if ( getComputedStyle( closestElement ).position !== 'static' ) {
34
30
  return closestElement;
35
31
  }
36
32
 
37
33
  // offsetParent is undocumented/draft.
38
- return /** @type {Node & { offsetParent: Node }} */ ( closestElement )
39
- .offsetParent;
34
+ return ( closestElement as HTMLElement ).offsetParent;
40
35
  }
@@ -2,10 +2,10 @@
2
2
  * Gets the height of the range without ignoring zero width rectangles, which
3
3
  * some browsers ignore when creating a union.
4
4
  *
5
- * @param {Range} range The range to check.
6
- * @return {number | undefined} Height of the range or undefined if the range has no client rectangles.
5
+ * @param range The range to check.
6
+ * @return Height of the range or undefined if the range has no client rectangles.
7
7
  */
8
- export default function getRangeHeight( range ) {
8
+ export default function getRangeHeight( range: Range ): number | undefined {
9
9
  const rects = Array.from( range.getClientRects() );
10
10
 
11
11
  if ( ! rects.length ) {
@@ -5,11 +5,11 @@ import { assertIsDefined } from '../utils/assert-is-defined';
5
5
  * can be found. Use instead of `Range.getBoundingClientRect()`, which is often
6
6
  * broken, especially for collapsed ranges.
7
7
  *
8
- * @param {Range} range The range.
8
+ * @param range The range.
9
9
  *
10
- * @return {DOMRect?} The rectangle.
10
+ * @return The rectangle.
11
11
  */
12
- export default function getRectangleFromRange( range ) {
12
+ export default function getRectangleFromRange( range: Range ): DOMRect | null {
13
13
  // For uncollapsed ranges, get the rectangle that bounds the contents of the
14
14
  // range; this a rectangle enclosing the union of the bounding rectangles
15
15
  // for all the elements in the range.
@@ -97,10 +97,7 @@ export default function getRectangleFromRange( range ) {
97
97
  let beforeRange;
98
98
  if ( before && before.nodeType === before.TEXT_NODE ) {
99
99
  beforeRange = ownerDocument.createRange();
100
- beforeRange.setStart(
101
- before,
102
- /** @type {Text} */ ( before ).length
103
- );
100
+ beforeRange.setStart( before, ( before as Text ).length );
104
101
  beforeRange.collapse( true );
105
102
  }
106
103
  let afterRange;
@@ -149,13 +146,10 @@ export default function getRectangleFromRange( range ) {
149
146
  rects.length === 1 &&
150
147
  startContainer.nodeType === startContainer.TEXT_NODE &&
151
148
  range.startOffset > 0 &&
152
- range.startOffset < /** @type {Text} */ ( startContainer ).length
149
+ range.startOffset < ( startContainer as Text ).length
153
150
  ) {
154
151
  assertIsDefined( ownerDocument, 'ownerDocument' );
155
- const measure = (
156
- /** @type {number} */ start,
157
- /** @type {number} */ end
158
- ) => {
152
+ const measure = ( start: number, end: number ) => {
159
153
  const charRange = ownerDocument.createRange();
160
154
  charRange.setStart( startContainer, start );
161
155
  charRange.setEnd( startContainer, end );
@@ -4,12 +4,15 @@ import getComputedStyle from './get-computed-style';
4
4
  * Given a DOM node, finds the closest scrollable container node or the node
5
5
  * itself, if scrollable.
6
6
  *
7
- * @param {Element | null} node Node from which to start.
8
- * @param {?string} direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').
9
- * Defaults to 'vertical'.
10
- * @return {Element | undefined} Scrollable container node, if found.
7
+ * @param node Node from which to start.
8
+ * @param direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').
9
+ * Defaults to 'vertical'.
10
+ * @return Scrollable container node, if found.
11
11
  */
12
- export default function getScrollContainer( node, direction = 'vertical' ) {
12
+ export default function getScrollContainer(
13
+ node: Element | null,
14
+ direction: 'vertical' | 'horizontal' | 'all' = 'vertical'
15
+ ): Element | undefined {
13
16
  if ( ! node ) {
14
17
  return undefined;
15
18
  }
@@ -43,8 +46,5 @@ export default function getScrollContainer( node, direction = 'vertical' ) {
43
46
  }
44
47
 
45
48
  // Continue traversing.
46
- return getScrollContainer(
47
- /** @type {Element} */ ( node.parentNode ),
48
- direction
49
- );
49
+ return getScrollContainer( node.parentNode as Element, direction );
50
50
  }
@@ -6,14 +6,19 @@ import getComputedStyle from './get-computed-style';
6
6
  * Gives the container a temporary high z-index (above any UI).
7
7
  * This is preferred over getting the UI nodes and set styles there.
8
8
  *
9
- * @param {Document} doc The document of the range.
10
- * @param {number} x Horizontal position within the current viewport.
11
- * @param {number} y Vertical position within the current viewport.
12
- * @param {HTMLElement} container Container in which the range is expected to be found.
9
+ * @param doc The document of the range.
10
+ * @param x Horizontal position within the current viewport.
11
+ * @param y Vertical position within the current viewport.
12
+ * @param container Container in which the range is expected to be found.
13
13
  *
14
- * @return {?Range} The best range for the given point.
14
+ * @return The best range for the given point.
15
15
  */
16
- export default function hiddenCaretRangeFromPoint( doc, x, y, container ) {
16
+ export default function hiddenCaretRangeFromPoint(
17
+ doc: Document,
18
+ x: number,
19
+ y: number,
20
+ container: HTMLElement
21
+ ): Range | null {
17
22
  const originalZIndex = container.style.zIndex;
18
23
  const originalPosition = container.style.position;
19
24
  const originalBorderRadius = container.style.borderRadius;
@@ -14,11 +14,13 @@ import isHTMLInputElement from './is-html-input-element';
14
14
  *
15
15
  * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply
16
16
  *
17
- * @param {Element} element The HTML element.
17
+ * @param element The HTML element.
18
18
  *
19
- * @return {boolean} Whether the input/textarea element has some "selection".
19
+ * @return Whether the input/textarea element has some "selection".
20
20
  */
21
- export default function inputFieldHasUncollapsedSelection( element ) {
21
+ export default function inputFieldHasUncollapsedSelection(
22
+ element: Element
23
+ ): boolean {
22
24
  if ( ! isHTMLInputElement( element ) && ! isTextField( element ) ) {
23
25
  return false;
24
26
  }
@@ -27,8 +29,8 @@ export default function inputFieldHasUncollapsedSelection( element ) {
27
29
  // `selectionEnd` on non-text <input> elements, so a try/catch construct is
28
30
  // necessary.
29
31
  try {
30
- const { selectionStart, selectionEnd } =
31
- /** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element );
32
+ const { selectionStart, selectionEnd } = element as
33
+ HTMLInputElement | HTMLTextAreaElement;
32
34
  return (
33
35
  // `null` means the input type doesn't implement selection, thus we
34
36
  // cannot determine whether the selection is collapsed, so we
@@ -4,11 +4,13 @@ import { assertIsDefined } from '../utils/assert-is-defined';
4
4
  * Given two DOM nodes, inserts the former in the DOM as the next sibling of
5
5
  * the latter.
6
6
  *
7
- * @param {Node} newNode Node to be inserted.
8
- * @param {Node} referenceNode Node after which to perform the insertion.
9
- * @return {void}
7
+ * @param newNode Node to be inserted.
8
+ * @param referenceNode Node after which to perform the insertion.
10
9
  */
11
- export default function insertAfter( newNode, referenceNode ) {
10
+ export default function insertAfter(
11
+ newNode: Node,
12
+ referenceNode: Node
13
+ ): void {
12
14
  assertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );
13
15
  referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
14
16
  }
@@ -12,13 +12,17 @@ import { scrollIfNoRange } from './scroll-if-no-range';
12
12
  * horizontal position by default. Set `onlyVertical` to true to check only
13
13
  * vertically.
14
14
  *
15
- * @param {HTMLElement} container Focusable element.
16
- * @param {boolean} isReverse Set to true to check left, false to check right.
17
- * @param {boolean} [onlyVertical=false] Set to true to check only vertical position.
15
+ * @param container Focusable element.
16
+ * @param isReverse Set to true to check left, false to check right.
17
+ * @param onlyVertical Set to true to check only vertical position.
18
18
  *
19
- * @return {boolean} True if at the edge, false if not.
19
+ * @return True if at the edge, false if not.
20
20
  */
21
- export default function isEdge( container, isReverse, onlyVertical = false ) {
21
+ export default function isEdge(
22
+ container: HTMLElement,
23
+ isReverse: boolean,
24
+ onlyVertical: boolean = false
25
+ ): boolean {
22
26
  if (
23
27
  isInputOrTextArea( container ) &&
24
28
  typeof container.selectionStart === 'number'
@@ -2,6 +2,8 @@
2
2
  * @param {Node | null | undefined} node
3
3
  * @return {node is Element} True if node is an Element node
4
4
  */
5
- export default function isElement( node ) {
5
+ export default function isElement(
6
+ node: Node | null | undefined
7
+ ): node is Element {
6
8
  return !! node && node.nodeType === node.ELEMENT_NODE;
7
9
  }
@@ -2,26 +2,24 @@
2
2
  * Recursively checks if an element is empty. An element is not empty if it
3
3
  * contains text or contains elements with attributes such as images.
4
4
  *
5
- * @param {Element} element The element to check.
5
+ * @param element The element to check.
6
6
  *
7
- * @return {boolean} Whether or not the element is empty.
7
+ * @return Whether or not the element is empty.
8
8
  */
9
- export default function isEmpty( element ) {
9
+ export default function isEmpty( element: Node ): boolean {
10
10
  switch ( element.nodeType ) {
11
11
  case element.TEXT_NODE:
12
12
  // We cannot use \s since it includes special spaces which we want
13
13
  // to preserve.
14
14
  return /^[ \f\n\r\t\v\u00a0]*$/.test( element.nodeValue || '' );
15
15
  case element.ELEMENT_NODE:
16
- if ( element.hasAttributes() ) {
16
+ if ( ( element as Element ).hasAttributes() ) {
17
17
  return false;
18
18
  } else if ( ! element.hasChildNodes() ) {
19
19
  return true;
20
20
  }
21
21
 
22
- return /** @type {Element[]} */ (
23
- Array.from( element.childNodes )
24
- ).every( isEmpty );
22
+ return Array.from( element.childNodes ).every( isEmpty );
25
23
  default:
26
24
  return true;
27
25
  }
@@ -11,11 +11,11 @@ const ZWNBSP = '\ufeff';
11
11
  * Check whether the contents of the element have been entirely selected.
12
12
  * Returns true if there is no possibility of selection.
13
13
  *
14
- * @param {HTMLElement} element The element to check.
14
+ * @param element The element to check.
15
15
  *
16
- * @return {boolean} True if entirely selected, false if not.
16
+ * @return True if entirely selected, false if not.
17
17
  */
18
- export default function isEntirelySelected( element ) {
18
+ export default function isEntirelySelected( element: HTMLElement ): boolean {
19
19
  if ( isInputOrTextArea( element ) ) {
20
20
  return (
21
21
  element.selectionStart === 0 &&
@@ -61,7 +61,7 @@ export default function isEntirelySelected( element ) {
61
61
  assertIsDefined( lastChild, 'lastChild' );
62
62
  const endContainerContentLength =
63
63
  endContainer.nodeType === endContainer.TEXT_NODE
64
- ? /** @type {Text} */ ( endContainer ).data.length
64
+ ? ( endContainer as Text ).data.length
65
65
  : endContainer.childNodes.length;
66
66
 
67
67
  return (
@@ -76,15 +76,18 @@ export default function isEntirelySelected( element ) {
76
76
  * Check whether the contents of the element have been entirely selected.
77
77
  * Returns true if there is no possibility of selection.
78
78
  *
79
- * @param {HTMLElement|Node} query The element to check.
80
- * @param {HTMLElement} container The container that we suspect "query" may be a first or last child of.
81
- * @param {"firstChild"|"lastChild"} propName "firstChild" or "lastChild"
79
+ * @param query The element to check.
80
+ * @param container The container that we suspect "query" may be a first or last child of.
81
+ * @param propName "firstChild" or "lastChild"
82
82
  *
83
- * @return {boolean} True if query is a deep first/last child of container, false otherwise.
83
+ * @return True if query is a deep first/last child of container, false otherwise.
84
84
  */
85
- function isDeepChild( query, container, propName ) {
86
- /** @type {HTMLElement | ChildNode | null} */
87
- let candidate = container;
85
+ function isDeepChild(
86
+ query: HTMLElement | Node,
87
+ container: HTMLElement,
88
+ propName: 'firstChild' | 'lastChild'
89
+ ): boolean {
90
+ let candidate: HTMLElement | ChildNode | null = container;
88
91
  do {
89
92
  if ( query === candidate ) {
90
93
  return true;
@@ -4,11 +4,13 @@ import isInputOrTextArea from './is-input-or-text-area';
4
4
  *
5
5
  * Detects if element is a form element.
6
6
  *
7
- * @param {Element} element The element to check.
7
+ * @param element The element to check.
8
8
  *
9
- * @return {boolean} True if form element and false otherwise.
9
+ * @return True if form element and false otherwise.
10
10
  */
11
- export default function isFormElement( element ) {
11
+ export default function isFormElement(
12
+ element: Element | null | undefined
13
+ ): boolean {
12
14
  if ( ! element ) {
13
15
  return false;
14
16
  }
@@ -8,6 +8,9 @@ import isEdge from './is-edge';
8
8
  *
9
9
  * @return {boolean} True if at the horizontal edge, false if not.
10
10
  */
11
- export default function isHorizontalEdge( container, isReverse ) {
11
+ export default function isHorizontalEdge(
12
+ container: HTMLElement,
13
+ isReverse: boolean
14
+ ): boolean {
12
15
  return isEdge( container, isReverse );
13
16
  }
@@ -2,6 +2,8 @@
2
2
  * @param {Node} node
3
3
  * @return {node is HTMLInputElement} Whether the node is an HTMLInputElement.
4
4
  */
5
- export default function isHTMLInputElement( node ) {
5
+ export default function isHTMLInputElement(
6
+ node: Node | null | undefined
7
+ ): node is HTMLInputElement {
6
8
  return node?.nodeName === 'INPUT';
7
9
  }
@@ -2,6 +2,8 @@
2
2
  * @param {Element} element
3
3
  * @return {element is HTMLInputElement | HTMLTextAreaElement} Whether the element is an input or textarea
4
4
  */
5
- export default function isInputOrTextArea( element ) {
5
+ export default function isInputOrTextArea(
6
+ element: Element
7
+ ): element is HTMLInputElement | HTMLTextAreaElement {
6
8
  return element.tagName === 'INPUT' || element.tagName === 'TEXTAREA';
7
9
  }