@wordpress/dom 4.57.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 (334) hide show
  1. package/README.md +23 -23
  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 +88 -133
  7. package/build/dom/clean-node-list.cjs.map +1 -7
  8. package/build/dom/compute-caret-rect.cjs +36 -36
  9. package/build/dom/compute-caret-rect.cjs.map +1 -7
  10. package/build/dom/document-has-selection.cjs +36 -31
  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 +35 -30
  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 +41 -48
  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 -133
  23. package/build/dom/get-rectangle-from-range.cjs.map +1 -7
  24. package/build/dom/get-scroll-container.cjs +47 -55
  25. package/build/dom/get-scroll-container.cjs.map +1 -7
  26. package/build/dom/hidden-caret-range-from-point.cjs +49 -43
  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 +49 -47
  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 +83 -98
  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 -40
  38. package/build/dom/is-empty.cjs.map +1 -7
  39. package/build/dom/is-entirely-selected.cjs +71 -71
  40. package/build/dom/is-entirely-selected.cjs.map +1 -7
  41. package/build/dom/is-form-element.cjs +34 -34
  42. package/build/dom/is-form-element.cjs.map +1 -7
  43. package/build/dom/is-horizontal-edge.cjs +32 -29
  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 +37 -34
  50. package/build/dom/is-number-input.cjs.map +1 -7
  51. package/build/dom/is-rtl.cjs +31 -29
  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 +46 -44
  56. package/build/dom/is-text-field.cjs.map +1 -7
  57. package/build/dom/is-vertical-edge.cjs +32 -29
  58. package/build/dom/is-vertical-edge.cjs.map +1 -7
  59. package/build/dom/place-caret-at-edge.cjs +76 -79
  60. package/build/dom/place-caret-at-edge.cjs.map +1 -7
  61. package/build/dom/place-caret-at-horizontal-edge.cjs +30 -29
  62. package/build/dom/place-caret-at-horizontal-edge.cjs.map +1 -7
  63. package/build/dom/place-caret-at-vertical-edge.cjs +31 -29
  64. package/build/dom/place-caret-at-vertical-edge.cjs.map +1 -7
  65. package/build/dom/remove-invalid-html.cjs +36 -32
  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 +35 -33
  72. package/build/dom/replace.cjs.map +1 -7
  73. package/build/dom/safe-html.cjs +46 -47
  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 +34 -32
  78. package/build/dom/strip-html.cjs.map +1 -7
  79. package/build/dom/types.cjs +5 -0
  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 -77
  85. package/build/focusable.cjs.map +1 -7
  86. package/build/index.cjs +58 -39
  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 +5 -0
  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 +17 -15
  96. package/build-module/data-transfer.mjs.map +1 -7
  97. package/build-module/dom/caret-range-from-point.mjs +28 -19
  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 +21 -25
  112. package/build-module/dom/get-offset-parent.mjs.map +1 -7
  113. package/build-module/dom/get-range-height.mjs +15 -12
  114. package/build-module/dom/get-range-height.mjs.map +1 -7
  115. package/build-module/dom/get-rectangle-from-range.mjs +78 -113
  116. package/build-module/dom/get-rectangle-from-range.mjs.map +1 -7
  117. package/build-module/dom/get-scroll-container.mjs +28 -32
  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 -23
  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 +9 -6
  129. package/build-module/dom/is-element.mjs.map +1 -7
  130. package/build-module/dom/is-empty.mjs +20 -21
  131. package/build-module/dom/is-empty.mjs.map +1 -7
  132. package/build-module/dom/is-entirely-selected.mjs +51 -47
  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 +9 -6
  139. package/build-module/dom/is-html-input-element.mjs.map +1 -7
  140. package/build-module/dom/is-input-or-text-area.mjs +9 -6
  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 -21
  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 +21 -14
  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 -0
  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 +96 -54
  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 +158 -134
  182. package/build-module/phrasing-content.mjs.map +1 -7
  183. package/build-module/tabbable.mjs +117 -52
  184. package/build-module/tabbable.mjs.map +1 -7
  185. package/build-module/types.mjs +0 -0
  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/data-transfer.d.ts +2 -2
  189. package/build-types/data-transfer.d.ts.map +1 -1
  190. package/build-types/dom/caret-range-from-point.d.ts +4 -4
  191. package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
  192. package/build-types/dom/clean-node-list.d.ts +6 -46
  193. package/build-types/dom/clean-node-list.d.ts.map +1 -1
  194. package/build-types/dom/compute-caret-rect.d.ts +2 -2
  195. package/build-types/dom/compute-caret-rect.d.ts.map +1 -1
  196. package/build-types/dom/document-has-selection.d.ts +2 -2
  197. package/build-types/dom/document-has-selection.d.ts.map +1 -1
  198. package/build-types/dom/document-has-text-selection.d.ts +2 -2
  199. package/build-types/dom/document-has-text-selection.d.ts.map +1 -1
  200. package/build-types/dom/document-has-uncollapsed-selection.d.ts +2 -2
  201. package/build-types/dom/document-has-uncollapsed-selection.d.ts.map +1 -1
  202. package/build-types/dom/get-computed-style.d.ts +3 -3
  203. package/build-types/dom/get-computed-style.d.ts.map +1 -1
  204. package/build-types/dom/get-offset-parent.d.ts +2 -2
  205. package/build-types/dom/get-offset-parent.d.ts.map +1 -1
  206. package/build-types/dom/get-range-height.d.ts +2 -2
  207. package/build-types/dom/get-range-height.d.ts.map +1 -1
  208. package/build-types/dom/get-rectangle-from-range.d.ts +2 -2
  209. package/build-types/dom/get-rectangle-from-range.d.ts.map +1 -1
  210. package/build-types/dom/get-scroll-container.d.ts +5 -5
  211. package/build-types/dom/get-scroll-container.d.ts.map +1 -1
  212. package/build-types/dom/hidden-caret-range-from-point.d.ts +5 -5
  213. package/build-types/dom/hidden-caret-range-from-point.d.ts.map +1 -1
  214. package/build-types/dom/index.d.ts.map +1 -1
  215. package/build-types/dom/input-field-has-uncollapsed-selection.d.ts +2 -2
  216. package/build-types/dom/input-field-has-uncollapsed-selection.d.ts.map +1 -1
  217. package/build-types/dom/insert-after.d.ts +2 -3
  218. package/build-types/dom/insert-after.d.ts.map +1 -1
  219. package/build-types/dom/is-edge.d.ts +4 -4
  220. package/build-types/dom/is-edge.d.ts.map +1 -1
  221. package/build-types/dom/is-element.d.ts.map +1 -1
  222. package/build-types/dom/is-empty.d.ts +3 -3
  223. package/build-types/dom/is-empty.d.ts.map +1 -1
  224. package/build-types/dom/is-entirely-selected.d.ts +2 -2
  225. package/build-types/dom/is-entirely-selected.d.ts.map +1 -1
  226. package/build-types/dom/is-form-element.d.ts +3 -3
  227. package/build-types/dom/is-form-element.d.ts.map +1 -1
  228. package/build-types/dom/is-horizontal-edge.d.ts.map +1 -1
  229. package/build-types/dom/is-html-input-element.d.ts +1 -1
  230. package/build-types/dom/is-html-input-element.d.ts.map +1 -1
  231. package/build-types/dom/is-input-or-text-area.d.ts.map +1 -1
  232. package/build-types/dom/is-number-input.d.ts +2 -2
  233. package/build-types/dom/is-number-input.d.ts.map +1 -1
  234. package/build-types/dom/is-rtl.d.ts +2 -2
  235. package/build-types/dom/is-rtl.d.ts.map +1 -1
  236. package/build-types/dom/is-selection-forward.d.ts +2 -2
  237. package/build-types/dom/is-selection-forward.d.ts.map +1 -1
  238. package/build-types/dom/is-text-field.d.ts +2 -2
  239. package/build-types/dom/is-text-field.d.ts.map +1 -1
  240. package/build-types/dom/is-vertical-edge.d.ts.map +1 -1
  241. package/build-types/dom/place-caret-at-edge.d.ts +3 -3
  242. package/build-types/dom/place-caret-at-edge.d.ts.map +1 -1
  243. package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
  244. package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
  245. package/build-types/dom/remove-invalid-html.d.ts +5 -4
  246. package/build-types/dom/remove-invalid-html.d.ts.map +1 -1
  247. package/build-types/dom/remove.d.ts +1 -2
  248. package/build-types/dom/remove.d.ts.map +1 -1
  249. package/build-types/dom/replace-tag.d.ts +3 -3
  250. package/build-types/dom/replace-tag.d.ts.map +1 -1
  251. package/build-types/dom/replace.d.ts +2 -3
  252. package/build-types/dom/replace.d.ts.map +1 -1
  253. package/build-types/dom/safe-html.d.ts +2 -2
  254. package/build-types/dom/safe-html.d.ts.map +1 -1
  255. package/build-types/dom/scroll-if-no-range.d.ts +5 -5
  256. package/build-types/dom/scroll-if-no-range.d.ts.map +1 -1
  257. package/build-types/dom/strip-html.d.ts +2 -2
  258. package/build-types/dom/strip-html.d.ts.map +1 -1
  259. package/build-types/dom/types.d.ts +32 -0
  260. package/build-types/dom/types.d.ts.map +1 -0
  261. package/build-types/dom/unwrap.d.ts +1 -3
  262. package/build-types/dom/unwrap.d.ts.map +1 -1
  263. package/build-types/dom/wrap.d.ts +2 -2
  264. package/build-types/dom/wrap.d.ts.map +1 -1
  265. package/build-types/focusable.d.ts +11 -30
  266. package/build-types/focusable.d.ts.map +1 -1
  267. package/build-types/index.d.ts +17 -0
  268. package/build-types/index.d.ts.map +1 -1
  269. package/build-types/phrasing-content.d.ts +9 -24
  270. package/build-types/phrasing-content.d.ts.map +1 -1
  271. package/build-types/tabbable.d.ts +10 -15
  272. package/build-types/tabbable.d.ts.map +1 -1
  273. package/build-types/types.d.ts +29 -0
  274. package/build-types/types.d.ts.map +1 -0
  275. package/package.json +6 -7
  276. package/src/{data-transfer.js → data-transfer.ts} +3 -3
  277. package/src/dom/{caret-range-from-point.js → caret-range-from-point.ts} +9 -5
  278. package/src/dom/{clean-node-list.js → clean-node-list.ts} +16 -24
  279. package/src/dom/{compute-caret-rect.js → compute-caret-rect.ts} +3 -3
  280. package/src/dom/{document-has-selection.js → document-has-selection.ts} +3 -3
  281. package/src/dom/{document-has-text-selection.js → document-has-text-selection.ts} +3 -3
  282. package/src/dom/{document-has-uncollapsed-selection.js → document-has-uncollapsed-selection.ts} +5 -3
  283. package/src/dom/{get-computed-style.js → get-computed-style.ts} +5 -3
  284. package/src/dom/{get-offset-parent.js → get-offset-parent.ts} +9 -14
  285. package/src/dom/{get-range-height.js → get-range-height.ts} +3 -3
  286. package/src/dom/{get-rectangle-from-range.js → get-rectangle-from-range.ts} +6 -12
  287. package/src/dom/{get-scroll-container.js → get-scroll-container.ts} +9 -9
  288. package/src/dom/{hidden-caret-range-from-point.js → hidden-caret-range-from-point.ts} +11 -6
  289. package/src/dom/{input-field-has-uncollapsed-selection.js → input-field-has-uncollapsed-selection.ts} +7 -5
  290. package/src/dom/{insert-after.js → insert-after.ts} +6 -4
  291. package/src/dom/{is-edge.js → is-edge.ts} +44 -48
  292. package/src/dom/{is-element.js → is-element.ts} +3 -1
  293. package/src/dom/{is-empty.js → is-empty.ts} +5 -7
  294. package/src/dom/{is-entirely-selected.js → is-entirely-selected.ts} +14 -11
  295. package/src/dom/{is-form-element.js → is-form-element.ts} +5 -3
  296. package/src/dom/{is-horizontal-edge.js → is-horizontal-edge.ts} +4 -1
  297. package/src/dom/{is-html-input-element.js → is-html-input-element.ts} +3 -1
  298. package/src/dom/{is-input-or-text-area.js → is-input-or-text-area.ts} +3 -1
  299. package/src/dom/{is-number-input.js → is-number-input.ts} +3 -3
  300. package/src/dom/{is-rtl.js → is-rtl.ts} +3 -3
  301. package/src/dom/{is-selection-forward.js → is-selection-forward.ts} +3 -3
  302. package/src/dom/{is-text-field.js → is-text-field.ts} +4 -4
  303. package/src/dom/{is-vertical-edge.js → is-vertical-edge.ts} +4 -1
  304. package/src/dom/{place-caret-at-edge.js → place-caret-at-edge.ts} +17 -9
  305. package/src/dom/{place-caret-at-horizontal-edge.js → place-caret-at-horizontal-edge.ts} +4 -1
  306. package/src/dom/{place-caret-at-vertical-edge.js → place-caret-at-vertical-edge.ts} +5 -1
  307. package/src/dom/{remove-invalid-html.js → remove-invalid-html.ts} +9 -4
  308. package/src/dom/{remove.js → remove.ts} +2 -3
  309. package/src/dom/{replace-tag.js → replace-tag.ts} +4 -4
  310. package/src/dom/{replace.js → replace.ts} +6 -4
  311. package/src/dom/{safe-html.js → safe-html.ts} +3 -3
  312. package/src/dom/{scroll-if-no-range.js → scroll-if-no-range.ts} +9 -5
  313. package/src/dom/{strip-html.js → strip-html.ts} +3 -3
  314. package/src/dom/test/{get-rectangle-from-range.browser.test.js → get-rectangle-from-range.browser.test.ts} +25 -25
  315. package/src/dom/types.ts +28 -0
  316. package/src/dom/{unwrap.js → unwrap.ts} +2 -4
  317. package/src/dom/{wrap.js → wrap.ts} +3 -3
  318. package/src/{focusable.js → focusable.ts} +34 -32
  319. package/src/index.ts +33 -0
  320. package/src/{phrasing-content.js → phrasing-content.ts} +15 -30
  321. package/src/{tabbable.js → tabbable.ts} +48 -39
  322. package/src/test/{dom.jsdom.test.js → dom.jsdom.test.ts} +30 -6
  323. package/src/test/{focusable.browser.test.js → focusable.browser.test.ts} +14 -13
  324. package/src/test/{tabbable.browser.test.js → tabbable.browser.test.ts} +3 -2
  325. package/src/types.ts +32 -0
  326. package/CHANGELOG.md +0 -317
  327. package/build/dom/index.cjs.map +0 -7
  328. package/build-module/dom/index.mjs.map +0 -7
  329. package/src/index.js +0 -12
  330. /package/src/dom/{index.js → index.ts} +0 -0
  331. /package/src/dom/test/{safe-html.jsdom.test.js → safe-html.jsdom.test.ts} +0 -0
  332. /package/src/dom/test/{strip-html.jsdom.test.js → strip-html.jsdom.test.ts} +0 -0
  333. /package/src/test/{focusable-area.jsdom.test.js → focusable-area.jsdom.test.ts} +0 -0
  334. /package/src/test/{utils.js → utils.ts} +0 -0
@@ -1,13 +1,18 @@
1
- // packages/dom/src/dom/replace.js
2
1
  import { assertIsDefined } from "../utils/assert-is-defined.mjs";
3
2
  import insertAfter from "./insert-after.mjs";
4
3
  import remove from "./remove.mjs";
4
+ // packages/dom/src/dom/replace.ts
5
+ /**
6
+ * Given two DOM nodes, replaces the former with the latter in the DOM.
7
+ *
8
+ * @param processedNode Node to be removed.
9
+ * @param newNode Node to be inserted in its place.
10
+ */
5
11
  function replace(processedNode, newNode) {
6
- assertIsDefined(processedNode.parentNode, "processedNode.parentNode");
7
- insertAfter(newNode, processedNode.parentNode);
8
- remove(processedNode);
12
+ assertIsDefined(processedNode.parentNode, "processedNode.parentNode");
13
+ insertAfter(newNode, processedNode.parentNode);
14
+ remove(processedNode);
9
15
  }
10
- export {
11
- replace as default
12
- };
13
- //# sourceMappingURL=replace.mjs.map
16
+ export { replace as default };
17
+
18
+ //# sourceMappingURL=replace.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/replace.js"],
4
- "sourcesContent": ["import { assertIsDefined } from '../utils/assert-is-defined';\nimport insertAfter from './insert-after';\nimport remove from './remove';\n\n/**\n * Given two DOM nodes, replaces the former with the latter in the DOM.\n *\n * @param {Element} processedNode Node to be removed.\n * @param {Element} newNode Node to be inserted in its place.\n * @return {void}\n */\nexport default function replace( processedNode, newNode ) {\n\tassertIsDefined( processedNode.parentNode, 'processedNode.parentNode' );\n\tinsertAfter( newNode, processedNode.parentNode );\n\tremove( processedNode );\n}\n"],
5
- "mappings": ";AAAA,SAAS,uBAAuB;AAChC,OAAO,iBAAiB;AACxB,OAAO,YAAY;AASJ,SAAR,QAA0B,eAAe,SAAU;AACzD,kBAAiB,cAAc,YAAY,0BAA2B;AACtE,cAAa,SAAS,cAAc,UAAW;AAC/C,SAAQ,aAAc;AACvB;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"replace.mjs","names":[],"sources":["../../src/dom/replace.ts"],"sourcesContent":["import { assertIsDefined } from '../utils/assert-is-defined';\nimport insertAfter from './insert-after';\nimport remove from './remove';\n\n/**\n * Given two DOM nodes, replaces the former with the latter in the DOM.\n *\n * @param processedNode Node to be removed.\n * @param newNode Node to be inserted in its place.\n */\nexport default function replace(\n\tprocessedNode: Element,\n\tnewNode: Element\n): void {\n\tassertIsDefined( processedNode.parentNode, 'processedNode.parentNode' );\n\tinsertAfter( newNode, processedNode.parentNode );\n\tremove( processedNode );\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAwB,QACvB,eACA,SACO;CACP,gBAAiB,cAAc,YAAY,0BAA2B;CACtE,YAAa,SAAS,cAAc,UAAW;CAC/C,OAAQ,aAAc;AACvB"}
@@ -1,27 +1,30 @@
1
- // packages/dom/src/dom/safe-html.js
2
1
  import remove from "./remove.mjs";
2
+ // packages/dom/src/dom/safe-html.ts
3
+ /**
4
+ * Strips scripts and on* attributes from HTML.
5
+ *
6
+ * @param html HTML to sanitize.
7
+ *
8
+ * @return The sanitized HTML.
9
+ */
3
10
  function safeHTML(html) {
4
- const { body } = document.implementation.createHTMLDocument("");
5
- body.innerHTML = html;
6
- const elements = body.getElementsByTagName("*");
7
- let elementIndex = elements.length;
8
- while (elementIndex--) {
9
- const element = elements[elementIndex];
10
- if (element.tagName === "SCRIPT") {
11
- remove(element);
12
- } else {
13
- let attributeIndex = element.attributes.length;
14
- while (attributeIndex--) {
15
- const { name: key } = element.attributes[attributeIndex];
16
- if (key.startsWith("on")) {
17
- element.removeAttribute(key);
18
- }
19
- }
20
- }
21
- }
22
- return body.innerHTML;
11
+ const { body } = document.implementation.createHTMLDocument("");
12
+ body.innerHTML = html;
13
+ const elements = body.getElementsByTagName("*");
14
+ let elementIndex = elements.length;
15
+ while (elementIndex--) {
16
+ const element = elements[elementIndex];
17
+ if (element.tagName === "SCRIPT") remove(element);
18
+ else {
19
+ let attributeIndex = element.attributes.length;
20
+ while (attributeIndex--) {
21
+ const { name: key } = element.attributes[attributeIndex];
22
+ if (key.startsWith("on")) element.removeAttribute(key);
23
+ }
24
+ }
25
+ }
26
+ return body.innerHTML;
23
27
  }
24
- export {
25
- safeHTML as default
26
- };
27
- //# sourceMappingURL=safe-html.mjs.map
28
+ export { safeHTML as default };
29
+
30
+ //# sourceMappingURL=safe-html.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/safe-html.js"],
4
- "sourcesContent": ["import remove from './remove';\n\n/**\n * Strips scripts and on* attributes from HTML.\n *\n * @param {string} html HTML to sanitize.\n *\n * @return {string} The sanitized HTML.\n */\nexport default function safeHTML( html ) {\n\tconst { body } = document.implementation.createHTMLDocument( '' );\n\tbody.innerHTML = html;\n\tconst elements = body.getElementsByTagName( '*' );\n\tlet elementIndex = elements.length;\n\n\twhile ( elementIndex-- ) {\n\t\tconst element = elements[ elementIndex ];\n\n\t\tif ( element.tagName === 'SCRIPT' ) {\n\t\t\tremove( element );\n\t\t} else {\n\t\t\tlet attributeIndex = element.attributes.length;\n\n\t\t\twhile ( attributeIndex-- ) {\n\t\t\t\tconst { name: key } = element.attributes[ attributeIndex ];\n\n\t\t\t\tif ( key.startsWith( 'on' ) ) {\n\t\t\t\t\telement.removeAttribute( key );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn body.innerHTML;\n}\n"],
5
- "mappings": ";AAAA,OAAO,YAAY;AASJ,SAAR,SAA2B,MAAO;AACxC,QAAM,EAAE,KAAK,IAAI,SAAS,eAAe,mBAAoB,EAAG;AAChE,OAAK,YAAY;AACjB,QAAM,WAAW,KAAK,qBAAsB,GAAI;AAChD,MAAI,eAAe,SAAS;AAE5B,SAAQ,gBAAiB;AACxB,UAAM,UAAU,SAAU,YAAa;AAEvC,QAAK,QAAQ,YAAY,UAAW;AACnC,aAAQ,OAAQ;AAAA,IACjB,OAAO;AACN,UAAI,iBAAiB,QAAQ,WAAW;AAExC,aAAQ,kBAAmB;AAC1B,cAAM,EAAE,MAAM,IAAI,IAAI,QAAQ,WAAY,cAAe;AAEzD,YAAK,IAAI,WAAY,IAAK,GAAI;AAC7B,kBAAQ,gBAAiB,GAAI;AAAA,QAC9B;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,SAAO,KAAK;AACb;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"safe-html.mjs","names":[],"sources":["../../src/dom/safe-html.ts"],"sourcesContent":["import remove from './remove';\n\n/**\n * Strips scripts and on* attributes from HTML.\n *\n * @param html HTML to sanitize.\n *\n * @return The sanitized HTML.\n */\nexport default function safeHTML( html: string ): string {\n\tconst { body } = document.implementation.createHTMLDocument( '' );\n\tbody.innerHTML = html;\n\tconst elements = body.getElementsByTagName( '*' );\n\tlet elementIndex = elements.length;\n\n\twhile ( elementIndex-- ) {\n\t\tconst element = elements[ elementIndex ];\n\n\t\tif ( element.tagName === 'SCRIPT' ) {\n\t\t\tremove( element );\n\t\t} else {\n\t\t\tlet attributeIndex = element.attributes.length;\n\n\t\t\twhile ( attributeIndex-- ) {\n\t\t\t\tconst { name: key } = element.attributes[ attributeIndex ];\n\n\t\t\t\tif ( key.startsWith( 'on' ) ) {\n\t\t\t\t\telement.removeAttribute( key );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn body.innerHTML;\n}\n"],"mappings":";;;;;;;;;AASA,SAAwB,SAAU,MAAuB;CACxD,MAAM,EAAE,SAAS,SAAS,eAAe,mBAAoB,EAAG;CAChE,KAAK,YAAY;CACjB,MAAM,WAAW,KAAK,qBAAsB,GAAI;CAChD,IAAI,eAAe,SAAS;CAE5B,OAAQ,gBAAiB;EACxB,MAAM,UAAU,SAAU;EAE1B,IAAK,QAAQ,YAAY,UACxB,OAAQ,OAAQ;OACV;GACN,IAAI,iBAAiB,QAAQ,WAAW;GAExC,OAAQ,kBAAmB;IAC1B,MAAM,EAAE,MAAM,QAAQ,QAAQ,WAAY;IAE1C,IAAK,IAAI,WAAY,IAAK,GACzB,QAAQ,gBAAiB,GAAI;GAE/B;EACD;CACD;CAEA,OAAO,KAAK;AACb"}
@@ -1,16 +1,23 @@
1
- // packages/dom/src/dom/scroll-if-no-range.js
1
+ // packages/dom/src/dom/scroll-if-no-range.ts
2
+ /**
3
+ * If no range range can be created or it is outside the container, the element
4
+ * may be out of view, so scroll it into view and try again.
5
+ *
6
+ * @param container The container to scroll.
7
+ * @param alignToTop True to align to top, false to bottom.
8
+ * @param callback The callback to create the range.
9
+ *
10
+ * @return The range returned by the callback.
11
+ */
2
12
  function scrollIfNoRange(container, alignToTop, callback) {
3
- let range = callback();
4
- if (!range || !range.startContainer || !container.contains(range.startContainer)) {
5
- container.scrollIntoView(alignToTop);
6
- range = callback();
7
- if (!range || !range.startContainer || !container.contains(range.startContainer)) {
8
- return null;
9
- }
10
- }
11
- return range;
13
+ let range = callback();
14
+ if (!range || !range.startContainer || !container.contains(range.startContainer)) {
15
+ container.scrollIntoView(alignToTop);
16
+ range = callback();
17
+ if (!range || !range.startContainer || !container.contains(range.startContainer)) return null;
18
+ }
19
+ return range;
12
20
  }
13
- export {
14
- scrollIfNoRange
15
- };
16
- //# sourceMappingURL=scroll-if-no-range.mjs.map
21
+ export { scrollIfNoRange };
22
+
23
+ //# sourceMappingURL=scroll-if-no-range.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/scroll-if-no-range.js"],
4
- "sourcesContent": ["/**\n * If no range range can be created or it is outside the container, the element\n * may be out of view, so scroll it into view and try again.\n *\n * @param {HTMLElement} container The container to scroll.\n * @param {boolean} alignToTop True to align to top, false to bottom.\n * @param {Function} callback The callback to create the range.\n *\n * @return {?Range} The range returned by the callback.\n */\nexport function scrollIfNoRange( container, alignToTop, callback ) {\n\tlet range = callback();\n\n\t// If no range range can be created or it is outside the container, the\n\t// element may be out of view.\n\tif (\n\t\t! range ||\n\t\t! range.startContainer ||\n\t\t! container.contains( range.startContainer )\n\t) {\n\t\tcontainer.scrollIntoView( alignToTop );\n\t\trange = callback();\n\n\t\tif (\n\t\t\t! range ||\n\t\t\t! range.startContainer ||\n\t\t\t! container.contains( range.startContainer )\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\treturn range;\n}\n"],
5
- "mappings": ";AAUO,SAAS,gBAAiB,WAAW,YAAY,UAAW;AAClE,MAAI,QAAQ,SAAS;AAIrB,MACC,CAAE,SACF,CAAE,MAAM,kBACR,CAAE,UAAU,SAAU,MAAM,cAAe,GAC1C;AACD,cAAU,eAAgB,UAAW;AACrC,YAAQ,SAAS;AAEjB,QACC,CAAE,SACF,CAAE,MAAM,kBACR,CAAE,UAAU,SAAU,MAAM,cAAe,GAC1C;AACD,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"scroll-if-no-range.mjs","names":[],"sources":["../../src/dom/scroll-if-no-range.ts"],"sourcesContent":["/**\n * If no range range can be created or it is outside the container, the element\n * may be out of view, so scroll it into view and try again.\n *\n * @param container The container to scroll.\n * @param alignToTop True to align to top, false to bottom.\n * @param callback The callback to create the range.\n *\n * @return The range returned by the callback.\n */\nexport function scrollIfNoRange(\n\tcontainer: HTMLElement,\n\talignToTop: boolean,\n\tcallback: () => Range | null\n): Range | null {\n\tlet range = callback();\n\n\t// If no range range can be created or it is outside the container, the\n\t// element may be out of view.\n\tif (\n\t\t! range ||\n\t\t! range.startContainer ||\n\t\t! container.contains( range.startContainer )\n\t) {\n\t\tcontainer.scrollIntoView( alignToTop );\n\t\trange = callback();\n\n\t\tif (\n\t\t\t! range ||\n\t\t\t! range.startContainer ||\n\t\t\t! container.contains( range.startContainer )\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\treturn range;\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,gBACf,WACA,YACA,UACe;CACf,IAAI,QAAQ,SAAS;CAIrB,IACC,CAAE,SACF,CAAE,MAAM,kBACR,CAAE,UAAU,SAAU,MAAM,cAAe,GAC1C;EACD,UAAU,eAAgB,UAAW;EACrC,QAAQ,SAAS;EAEjB,IACC,CAAE,SACF,CAAE,MAAM,kBACR,CAAE,UAAU,SAAU,MAAM,cAAe,GAE3C,OAAO;CAET;CAEA,OAAO;AACR"}
@@ -1,12 +1,18 @@
1
- // packages/dom/src/dom/strip-html.js
2
1
  import safeHTML from "./safe-html.mjs";
2
+ // packages/dom/src/dom/strip-html.ts
3
+ /**
4
+ * Removes any HTML tags from the provided string.
5
+ *
6
+ * @param html The string containing html.
7
+ *
8
+ * @return The text content with any html removed.
9
+ */
3
10
  function stripHTML(html) {
4
- html = safeHTML(html);
5
- const doc = document.implementation.createHTMLDocument("");
6
- doc.body.innerHTML = html;
7
- return doc.body.textContent || "";
11
+ html = safeHTML(html);
12
+ const doc = document.implementation.createHTMLDocument("");
13
+ doc.body.innerHTML = html;
14
+ return doc.body.textContent || "";
8
15
  }
9
- export {
10
- stripHTML as default
11
- };
12
- //# sourceMappingURL=strip-html.mjs.map
16
+ export { stripHTML as default };
17
+
18
+ //# sourceMappingURL=strip-html.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/strip-html.js"],
4
- "sourcesContent": ["import safeHTML from './safe-html';\n\n/**\n * Removes any HTML tags from the provided string.\n *\n * @param {string} html The string containing html.\n *\n * @return {string} The text content with any html removed.\n */\nexport default function stripHTML( html ) {\n\t// Remove any script tags or on* attributes otherwise their *contents* will be left\n\t// in place following removal of HTML tags.\n\thtml = safeHTML( html );\n\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\tdoc.body.innerHTML = html;\n\treturn doc.body.textContent || '';\n}\n"],
5
- "mappings": ";AAAA,OAAO,cAAc;AASN,SAAR,UAA4B,MAAO;AAGzC,SAAO,SAAU,IAAK;AAEtB,QAAM,MAAM,SAAS,eAAe,mBAAoB,EAAG;AAC3D,MAAI,KAAK,YAAY;AACrB,SAAO,IAAI,KAAK,eAAe;AAChC;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"strip-html.mjs","names":[],"sources":["../../src/dom/strip-html.ts"],"sourcesContent":["import safeHTML from './safe-html';\n\n/**\n * Removes any HTML tags from the provided string.\n *\n * @param html The string containing html.\n *\n * @return The text content with any html removed.\n */\nexport default function stripHTML( html: string ): string {\n\t// Remove any script tags or on* attributes otherwise their *contents* will be left\n\t// in place following removal of HTML tags.\n\thtml = safeHTML( html );\n\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\tdoc.body.innerHTML = html;\n\treturn doc.body.textContent || '';\n}\n"],"mappings":";;;;;;;;;AASA,SAAwB,UAAW,MAAuB;CAGzD,OAAO,SAAU,IAAK;CAEtB,MAAM,MAAM,SAAS,eAAe,mBAAoB,EAAG;CAC3D,IAAI,KAAK,YAAY;CACrB,OAAO,IAAI,KAAK,eAAe;AAChC"}
File without changes
@@ -1,14 +1,16 @@
1
- // packages/dom/src/dom/unwrap.js
2
1
  import { assertIsDefined } from "../utils/assert-is-defined.mjs";
2
+ // packages/dom/src/dom/unwrap.ts
3
+ /**
4
+ * Unwrap the given node. This means any child nodes are moved to the parent.
5
+ *
6
+ * @param node The node to unwrap.
7
+ */
3
8
  function unwrap(node) {
4
- const parent = node.parentNode;
5
- assertIsDefined(parent, "node.parentNode");
6
- while (node.firstChild) {
7
- parent.insertBefore(node.firstChild, node);
8
- }
9
- parent.removeChild(node);
9
+ const parent = node.parentNode;
10
+ assertIsDefined(parent, "node.parentNode");
11
+ while (node.firstChild) parent.insertBefore(node.firstChild, node);
12
+ parent.removeChild(node);
10
13
  }
11
- export {
12
- unwrap as default
13
- };
14
- //# sourceMappingURL=unwrap.mjs.map
14
+ export { unwrap as default };
15
+
16
+ //# sourceMappingURL=unwrap.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/unwrap.js"],
4
- "sourcesContent": ["import { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Unwrap the given node. This means any child nodes are moved to the parent.\n *\n * @param {Node} node The node to unwrap.\n *\n * @return {void}\n */\nexport default function unwrap( node ) {\n\tconst parent = node.parentNode;\n\n\tassertIsDefined( parent, 'node.parentNode' );\n\n\twhile ( node.firstChild ) {\n\t\tparent.insertBefore( node.firstChild, node );\n\t}\n\n\tparent.removeChild( node );\n}\n"],
5
- "mappings": ";AAAA,SAAS,uBAAuB;AASjB,SAAR,OAAyB,MAAO;AACtC,QAAM,SAAS,KAAK;AAEpB,kBAAiB,QAAQ,iBAAkB;AAE3C,SAAQ,KAAK,YAAa;AACzB,WAAO,aAAc,KAAK,YAAY,IAAK;AAAA,EAC5C;AAEA,SAAO,YAAa,IAAK;AAC1B;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"unwrap.mjs","names":[],"sources":["../../src/dom/unwrap.ts"],"sourcesContent":["import { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Unwrap the given node. This means any child nodes are moved to the parent.\n *\n * @param node The node to unwrap.\n */\nexport default function unwrap( node: Node ): void {\n\tconst parent = node.parentNode;\n\n\tassertIsDefined( parent, 'node.parentNode' );\n\n\twhile ( node.firstChild ) {\n\t\tparent.insertBefore( node.firstChild, node );\n\t}\n\n\tparent.removeChild( node );\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,OAAQ,MAAmB;CAClD,MAAM,SAAS,KAAK;CAEpB,gBAAiB,QAAQ,iBAAkB;CAE3C,OAAQ,KAAK,YACZ,OAAO,aAAc,KAAK,YAAY,IAAK;CAG5C,OAAO,YAAa,IAAK;AAC1B"}
@@ -1,11 +1,16 @@
1
- // packages/dom/src/dom/wrap.js
2
1
  import { assertIsDefined } from "../utils/assert-is-defined.mjs";
2
+ // packages/dom/src/dom/wrap.ts
3
+ /**
4
+ * Wraps the given node with a new node with the given tag name.
5
+ *
6
+ * @param newNode The node to insert.
7
+ * @param referenceNode The node to wrap.
8
+ */
3
9
  function wrap(newNode, referenceNode) {
4
- assertIsDefined(referenceNode.parentNode, "referenceNode.parentNode");
5
- referenceNode.parentNode.insertBefore(newNode, referenceNode);
6
- newNode.appendChild(referenceNode);
10
+ assertIsDefined(referenceNode.parentNode, "referenceNode.parentNode");
11
+ referenceNode.parentNode.insertBefore(newNode, referenceNode);
12
+ newNode.appendChild(referenceNode);
7
13
  }
8
- export {
9
- wrap as default
10
- };
11
- //# sourceMappingURL=wrap.mjs.map
14
+ export { wrap as default };
15
+
16
+ //# sourceMappingURL=wrap.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/dom/wrap.js"],
4
- "sourcesContent": ["import { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Wraps the given node with a new node with the given tag name.\n *\n * @param {Element} newNode The node to insert.\n * @param {Element} referenceNode The node to wrap.\n */\nexport default function wrap( newNode, referenceNode ) {\n\tassertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );\n\treferenceNode.parentNode.insertBefore( newNode, referenceNode );\n\tnewNode.appendChild( referenceNode );\n}\n"],
5
- "mappings": ";AAAA,SAAS,uBAAuB;AAQjB,SAAR,KAAuB,SAAS,eAAgB;AACtD,kBAAiB,cAAc,YAAY,0BAA2B;AACtE,gBAAc,WAAW,aAAc,SAAS,aAAc;AAC9D,UAAQ,YAAa,aAAc;AACpC;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"wrap.mjs","names":[],"sources":["../../src/dom/wrap.ts"],"sourcesContent":["import { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Wraps the given node with a new node with the given tag name.\n *\n * @param newNode The node to insert.\n * @param referenceNode The node to wrap.\n */\nexport default function wrap( newNode: Element, referenceNode: Element ) {\n\tassertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );\n\treferenceNode.parentNode.insertBefore( newNode, referenceNode );\n\tnewNode.appendChild( referenceNode );\n}\n"],"mappings":";;;;;;;;AAQA,SAAwB,KAAM,SAAkB,eAAyB;CACxE,gBAAiB,cAAc,YAAY,0BAA2B;CACtE,cAAc,WAAW,aAAc,SAAS,aAAc;CAC9D,QAAQ,YAAa,aAAc;AACpC"}
@@ -1,62 +1,104 @@
1
- // packages/dom/src/focusable.js
1
+ // packages/dom/src/focusable.ts
2
+ /**
3
+ * References:
4
+ *
5
+ * Focusable:
6
+ * - https://www.w3.org/TR/html5/editing.html#focus-management
7
+ *
8
+ * Sequential focus navigation:
9
+ * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute
10
+ *
11
+ * Disabled elements:
12
+ * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements
13
+ *
14
+ * getClientRects algorithm (requiring layout box):
15
+ * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface
16
+ *
17
+ * AREA elements associated with an IMG:
18
+ * - https://w3c.github.io/html/editing.html#data-model
19
+ */
20
+ /**
21
+ * Returns a CSS selector used to query for focusable elements.
22
+ *
23
+ * @param sequential If set, only query elements that are sequentially
24
+ * focusable. Non-interactive elements with a
25
+ * negative `tabindex` are focusable but not
26
+ * sequentially focusable.
27
+ * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
28
+ *
29
+ * @return CSS selector.
30
+ */
2
31
  function buildSelector(sequential) {
3
- return [
4
- sequential ? '[tabindex]:not([tabindex^="-"])' : "[tabindex]",
5
- "a[href]",
6
- "button:not([disabled])",
7
- 'input:not([type="hidden"]):not([disabled])',
8
- "select:not([disabled])",
9
- "textarea:not([disabled])",
10
- 'iframe:not([tabindex^="-"])',
11
- "object",
12
- "embed",
13
- "summary",
14
- "area[href]",
15
- "[contenteditable]:not([contenteditable=false])"
16
- ].join(",");
32
+ return [
33
+ sequential ? "[tabindex]:not([tabindex^=\"-\"])" : "[tabindex]",
34
+ "a[href]",
35
+ "button:not([disabled])",
36
+ "input:not([type=\"hidden\"]):not([disabled])",
37
+ "select:not([disabled])",
38
+ "textarea:not([disabled])",
39
+ "iframe:not([tabindex^=\"-\"])",
40
+ "object",
41
+ "embed",
42
+ "summary",
43
+ "area[href]",
44
+ "[contenteditable]:not([contenteditable=false])"
45
+ ].join(",");
17
46
  }
47
+ /**
48
+ * Returns true if the specified element has a layout box and is not hidden by
49
+ * CSS visibility or content visibility.
50
+ *
51
+ * @param element DOM element to test.
52
+ *
53
+ * @return Whether element is visible.
54
+ */
18
55
  function isVisible(element) {
19
- if (typeof element.checkVisibility === "function") {
20
- if (!element.checkVisibility({ visibilityProperty: true })) {
21
- return false;
22
- }
23
- } else {
24
- const visibility = element.ownerDocument.defaultView?.getComputedStyle(
25
- element
26
- ).visibility;
27
- if (visibility === "hidden" || visibility === "collapse") {
28
- return false;
29
- }
30
- }
31
- return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
56
+ if (typeof element.checkVisibility === "function") {
57
+ if (!element.checkVisibility({ visibilityProperty: true })) return false;
58
+ } else {
59
+ const visibility = element.ownerDocument.defaultView?.getComputedStyle(element).visibility;
60
+ if (visibility === "hidden" || visibility === "collapse") return false;
61
+ }
62
+ return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
32
63
  }
64
+ /**
65
+ * Returns true if the specified area element is a valid focusable element, or
66
+ * false otherwise. Area is only focusable if within a map where a named map
67
+ * referenced by an image somewhere in the document.
68
+ *
69
+ * @param element DOM area element to test.
70
+ *
71
+ * @return Whether area element is valid for focus.
72
+ */
33
73
  function isValidFocusableArea(element) {
34
- const map = element.closest("map[name]");
35
- if (!map) {
36
- return false;
37
- }
38
- const img = element.ownerDocument.querySelector(
39
- 'img[usemap="#' + map.name + '"]'
40
- );
41
- return !!img && !img.closest("[inert]") && isVisible(img);
74
+ const map = element.closest("map[name]");
75
+ if (!map) return false;
76
+ const img = element.ownerDocument.querySelector("img[usemap=\"#" + map.name + "\"]");
77
+ return !!img && !img.closest("[inert]") && isVisible(img);
42
78
  }
79
+ /**
80
+ * Returns all focusable elements within a given context.
81
+ *
82
+ * @param context Element in which to search.
83
+ * @param options
84
+ * @param [options.sequential] If set, only return elements that are
85
+ * sequentially focusable.
86
+ * Non-interactive elements with a
87
+ * negative `tabindex` are focusable but
88
+ * not sequentially focusable.
89
+ * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
90
+ *
91
+ * @return Focusable elements.
92
+ */
43
93
  function find(context, { sequential = false } = {}) {
44
- const elements = context.querySelectorAll(buildSelector(sequential));
45
- return Array.from(elements).filter((element) => {
46
- const { nodeName } = element;
47
- if ("AREA" === nodeName) {
48
- return isValidFocusableArea(
49
- /** @type {HTMLAreaElement} */
50
- element
51
- );
52
- }
53
- if (element.closest("[inert]")) {
54
- return false;
55
- }
56
- return isVisible(element);
57
- });
94
+ const elements = context.querySelectorAll(buildSelector(sequential));
95
+ return Array.from(elements).filter((element) => {
96
+ const { nodeName } = element;
97
+ if ("AREA" === nodeName) return isValidFocusableArea(element);
98
+ if (element.closest("[inert]")) return false;
99
+ return isVisible(element);
100
+ });
58
101
  }
59
- export {
60
- find
61
- };
62
- //# sourceMappingURL=focusable.mjs.map
102
+ export { find };
103
+
104
+ //# sourceMappingURL=focusable.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/focusable.js"],
4
- "sourcesContent": ["/**\n * References:\n *\n * Focusable:\n * - https://www.w3.org/TR/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\n/**\n * Returns a CSS selector used to query for focusable elements.\n *\n * @param {boolean} sequential If set, only query elements that are sequentially\n * focusable. Non-interactive elements with a\n * negative `tabindex` are focusable but not\n * sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {string} CSS selector.\n */\nfunction buildSelector( sequential ) {\n\treturn [\n\t\tsequential ? '[tabindex]:not([tabindex^=\"-\"])' : '[tabindex]',\n\t\t'a[href]',\n\t\t'button:not([disabled])',\n\t\t'input:not([type=\"hidden\"]):not([disabled])',\n\t\t'select:not([disabled])',\n\t\t'textarea:not([disabled])',\n\t\t'iframe:not([tabindex^=\"-\"])',\n\t\t'object',\n\t\t'embed',\n\t\t'summary',\n\t\t'area[href]',\n\t\t'[contenteditable]:not([contenteditable=false])',\n\t].join( ',' );\n}\n\n/**\n * Returns true if the specified element has a layout box and is not hidden by\n * CSS visibility or content visibility.\n *\n * @param {HTMLElement} element DOM element to test.\n *\n * @return {boolean} Whether element is visible.\n */\nfunction isVisible( element ) {\n\tif ( typeof element.checkVisibility === 'function' ) {\n\t\tif ( ! element.checkVisibility( { visibilityProperty: true } ) ) {\n\t\t\treturn false;\n\t\t}\n\t} else {\n\t\tconst visibility =\n\t\t\telement.ownerDocument.defaultView?.getComputedStyle(\n\t\t\t\telement\n\t\t\t).visibility;\n\t\tif ( visibility === 'hidden' || visibility === 'collapse' ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param {HTMLAreaElement} element DOM area element to test.\n *\n * @return {boolean} Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element ) {\n\t/** @type {HTMLMapElement | null} */\n\tconst map = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\t/** @type {HTMLImageElement | null} */\n\tconst img = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && ! img.closest( '[inert]' ) && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param {Element} context Element in which to search.\n * @param {Object} options\n * @param {boolean} [options.sequential] If set, only return elements that are\n * sequentially focusable.\n * Non-interactive elements with a\n * negative `tabindex` are focusable but\n * not sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {HTMLElement[]} Focusable elements.\n */\nexport function find( context, { sequential = false } = {} ) {\n\t/** @type {NodeListOf<HTMLElement>} */\n\tconst elements = context.querySelectorAll( buildSelector( sequential ) );\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\t// The mapped image determines whether this region is visible or inert.\n\t\t\treturn isValidFocusableArea(\n\t\t\t\t/** @type {HTMLAreaElement} */ ( element )\n\t\t\t);\n\t\t}\n\n\t\t// Elements inside an inert subtree are not focusable.\n\t\tif ( element.closest( '[inert]' ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn isVisible( element );\n\t} );\n}\n"],
5
- "mappings": ";AA8BA,SAAS,cAAe,YAAa;AACpC,SAAO;AAAA,IACN,aAAa,oCAAoC;AAAA,IACjD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,EAAE,KAAM,GAAI;AACb;AAUA,SAAS,UAAW,SAAU;AAC7B,MAAK,OAAO,QAAQ,oBAAoB,YAAa;AACpD,QAAK,CAAE,QAAQ,gBAAiB,EAAE,oBAAoB,KAAK,CAAE,GAAI;AAChE,aAAO;AAAA,IACR;AAAA,EACD,OAAO;AACN,UAAM,aACL,QAAQ,cAAc,aAAa;AAAA,MAClC;AAAA,IACD,EAAE;AACH,QAAK,eAAe,YAAY,eAAe,YAAa;AAC3D,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SACC,QAAQ,cAAc,KACtB,QAAQ,eAAe,KACvB,QAAQ,eAAe,EAAE,SAAS;AAEpC;AAWA,SAAS,qBAAsB,SAAU;AAExC,QAAM,MAAM,QAAQ,QAAS,WAAY;AACzC,MAAK,CAAE,KAAM;AACZ,WAAO;AAAA,EACR;AAGA,QAAM,MAAM,QAAQ,cAAc;AAAA,IACjC,kBAAkB,IAAI,OAAO;AAAA,EAC9B;AACA,SAAO,CAAC,CAAE,OAAO,CAAE,IAAI,QAAS,SAAU,KAAK,UAAW,GAAI;AAC/D;AAgBO,SAAS,KAAM,SAAS,EAAE,aAAa,MAAM,IAAI,CAAC,GAAI;AAE5D,QAAM,WAAW,QAAQ,iBAAkB,cAAe,UAAW,CAAE;AAEvE,SAAO,MAAM,KAAM,QAAS,EAAE,OAAQ,CAAE,YAAa;AACpD,UAAM,EAAE,SAAS,IAAI;AACrB,QAAK,WAAW,UAAW;AAE1B,aAAO;AAAA;AAAA,QAC2B;AAAA,MAClC;AAAA,IACD;AAGA,QAAK,QAAQ,QAAS,SAAU,GAAI;AACnC,aAAO;AAAA,IACR;AAEA,WAAO,UAAW,OAAQ;AAAA,EAC3B,CAAE;AACH;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"focusable.mjs","names":[],"sources":["../src/focusable.ts"],"sourcesContent":["import type { FindFocusableOptions } from './types';\n\n/**\n * References:\n *\n * Focusable:\n * - https://www.w3.org/TR/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\n/**\n * Returns a CSS selector used to query for focusable elements.\n *\n * @param sequential If set, only query elements that are sequentially\n * focusable. Non-interactive elements with a\n * negative `tabindex` are focusable but not\n * sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return CSS selector.\n */\nfunction buildSelector( sequential: boolean ): string {\n\treturn [\n\t\tsequential ? '[tabindex]:not([tabindex^=\"-\"])' : '[tabindex]',\n\t\t'a[href]',\n\t\t'button:not([disabled])',\n\t\t'input:not([type=\"hidden\"]):not([disabled])',\n\t\t'select:not([disabled])',\n\t\t'textarea:not([disabled])',\n\t\t'iframe:not([tabindex^=\"-\"])',\n\t\t'object',\n\t\t'embed',\n\t\t'summary',\n\t\t'area[href]',\n\t\t'[contenteditable]:not([contenteditable=false])',\n\t].join( ',' );\n}\n\n/**\n * Returns true if the specified element has a layout box and is not hidden by\n * CSS visibility or content visibility.\n *\n * @param element DOM element to test.\n *\n * @return Whether element is visible.\n */\nfunction isVisible( element: HTMLElement ): boolean {\n\tif ( typeof element.checkVisibility === 'function' ) {\n\t\tif ( ! element.checkVisibility( { visibilityProperty: true } ) ) {\n\t\t\treturn false;\n\t\t}\n\t} else {\n\t\tconst visibility =\n\t\t\telement.ownerDocument.defaultView?.getComputedStyle(\n\t\t\t\telement\n\t\t\t).visibility;\n\t\tif ( visibility === 'hidden' || visibility === 'collapse' ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param element DOM area element to test.\n *\n * @return Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element: HTMLAreaElement ): boolean {\n\tconst map: HTMLMapElement | null = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\tconst img: HTMLImageElement | null = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && ! img.closest( '[inert]' ) && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param context Element in which to search.\n * @param options\n * @param [options.sequential] If set, only return elements that are\n * sequentially focusable.\n * Non-interactive elements with a\n * negative `tabindex` are focusable but\n * not sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return Focusable elements.\n */\nexport function find(\n\tcontext: Element,\n\t{ sequential = false }: FindFocusableOptions = {}\n): HTMLElement[] {\n\tconst elements: NodeListOf< HTMLElement > = context.querySelectorAll(\n\t\tbuildSelector( sequential )\n\t);\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\t// The mapped image determines whether this region is visible or inert.\n\t\t\treturn isValidFocusableArea( element as HTMLAreaElement );\n\t\t}\n\n\t\t// Elements inside an inert subtree are not focusable.\n\t\tif ( element.closest( '[inert]' ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn isVisible( element );\n\t} );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAS,cAAe,YAA8B;CACrD,OAAO;EACN,aAAa,sCAAoC;EACjD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC,CAAC,KAAM,GAAI;AACb;;;;;;;;;AAUA,SAAS,UAAW,SAAgC;CACnD,IAAK,OAAO,QAAQ,oBAAoB,YAClC;MAAA,CAAE,QAAQ,gBAAiB,EAAE,oBAAoB,KAAK,CAAE,GAC5D,OAAO;CAAA,OAEF;EACN,MAAM,aACL,QAAQ,cAAc,aAAa,iBAClC,OACD,CAAC,CAAC;EACH,IAAK,eAAe,YAAY,eAAe,YAC9C,OAAO;CAET;CAEA,OACC,QAAQ,cAAc,KACtB,QAAQ,eAAe,KACvB,QAAQ,eAAe,CAAC,CAAC,SAAS;AAEpC;;;;;;;;;;AAWA,SAAS,qBAAsB,SAAoC;CAClE,MAAM,MAA6B,QAAQ,QAAS,WAAY;CAChE,IAAK,CAAE,KACN,OAAO;CAGR,MAAM,MAA+B,QAAQ,cAAc,cAC1D,mBAAkB,IAAI,OAAO,KAC9B;CACA,OAAO,CAAC,CAAE,OAAO,CAAE,IAAI,QAAS,SAAU,KAAK,UAAW,GAAI;AAC/D;;;;;;;;;;;;;;;AAgBA,SAAgB,KACf,SACA,EAAE,aAAa,UAAgC,CAAC,GAChC;CAChB,MAAM,WAAsC,QAAQ,iBACnD,cAAe,UAAW,CAC3B;CAEA,OAAO,MAAM,KAAM,QAAS,CAAC,CAAC,QAAU,YAAa;EACpD,MAAM,EAAE,aAAa;EACrB,IAAK,WAAW,UAEf,OAAO,qBAAsB,OAA2B;EAIzD,IAAK,QAAQ,QAAS,SAAU,GAC/B,OAAO;EAGR,OAAO,UAAW,OAAQ;CAC3B,CAAE;AACH"}
@@ -1,11 +1,17 @@
1
- // packages/dom/src/index.js
2
1
  import * as focusable from "./focusable.mjs";
3
2
  import * as tabbable from "./tabbable.mjs";
4
3
  export * from "./dom/index.mjs";
5
4
  export * from "./phrasing-content.mjs";
6
5
  export * from "./data-transfer.mjs";
7
- var focus = { focusable, tabbable };
8
- export {
9
- focus
6
+ // packages/dom/src/index.ts
7
+ /**
8
+ * Object grouping `focusable` and `tabbable` utils
9
+ * under the keys with the same name.
10
+ */
11
+ const focus = {
12
+ focusable,
13
+ tabbable
10
14
  };
11
- //# sourceMappingURL=index.mjs.map
15
+ export { focus };
16
+
17
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/index.js"],
4
- "sourcesContent": ["import * as focusable from './focusable';\nimport * as tabbable from './tabbable';\n\n/**\n * Object grouping `focusable` and `tabbable` utils\n * under the keys with the same name.\n */\nexport const focus = { focusable, tabbable };\n\nexport * from './dom';\nexport * from './phrasing-content';\nexport * from './data-transfer';\n"],
5
- "mappings": ";AAAA,YAAY,eAAe;AAC3B,YAAY,cAAc;AAQ1B,cAAc;AACd,cAAc;AACd,cAAc;AAJP,IAAM,QAAQ,EAAE,WAAW,SAAS;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import * as focusable from './focusable';\nimport * as tabbable from './tabbable';\n\n/**\n * Object grouping `focusable` and `tabbable` utils\n * under the keys with the same name.\n */\nexport const focus = { focusable, tabbable };\n\nexport * from './dom';\nexport * from './phrasing-content';\nexport * from './data-transfer';\n\n/**\n * Schema of the content allowed inside an element, keyed by tag name.\n */\nexport type { ContentSchema } from './types';\n\n/**\n * The attributes and children allowed for an element in a `ContentSchema`.\n */\nexport type { SemanticElementDefinition } from './types';\n\n/**\n * Schema that `cleanNodeList` and `removeInvalidHTML` clean HTML against,\n * keyed by tag name.\n */\nexport type { Schema } from './dom/types';\n\n/**\n * The rules for a single tag in a `Schema`.\n */\nexport type { SchemaItem } from './dom/types';\n"],"mappings":";;;;;;;;;;AAOA,MAAa,QAAQ;CAAE;CAAW;AAAS"}