@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.
- package/README.md +23 -23
- package/build/data-transfer.cjs +20 -38
- package/build/data-transfer.cjs.map +1 -7
- package/build/dom/caret-range-from-point.cjs +31 -38
- package/build/dom/caret-range-from-point.cjs.map +1 -7
- package/build/dom/clean-node-list.cjs +88 -133
- package/build/dom/clean-node-list.cjs.map +1 -7
- package/build/dom/compute-caret-rect.cjs +36 -36
- package/build/dom/compute-caret-rect.cjs.map +1 -7
- package/build/dom/document-has-selection.cjs +36 -31
- package/build/dom/document-has-selection.cjs.map +1 -7
- package/build/dom/document-has-text-selection.cjs +24 -30
- package/build/dom/document-has-text-selection.cjs.map +1 -7
- package/build/dom/document-has-uncollapsed-selection.cjs +35 -30
- package/build/dom/document-has-uncollapsed-selection.cjs.map +1 -7
- package/build/dom/get-computed-style.cjs +14 -30
- package/build/dom/get-computed-style.cjs.map +1 -7
- package/build/dom/get-offset-parent.cjs +41 -48
- package/build/dom/get-offset-parent.cjs.map +1 -7
- package/build/dom/get-range-height.cjs +18 -31
- package/build/dom/get-range-height.cjs.map +1 -7
- package/build/dom/get-rectangle-from-range.cjs +82 -133
- package/build/dom/get-rectangle-from-range.cjs.map +1 -7
- package/build/dom/get-scroll-container.cjs +47 -55
- package/build/dom/get-scroll-container.cjs.map +1 -7
- package/build/dom/hidden-caret-range-from-point.cjs +49 -43
- package/build/dom/hidden-caret-range-from-point.cjs.map +1 -7
- package/build/dom/index.cjs +233 -110
- package/build/dom/input-field-has-uncollapsed-selection.cjs +49 -47
- package/build/dom/input-field-has-uncollapsed-selection.cjs.map +1 -7
- package/build/dom/insert-after.cjs +17 -27
- package/build/dom/insert-after.cjs.map +1 -7
- package/build/dom/is-edge.cjs +83 -98
- package/build/dom/is-edge.cjs.map +1 -7
- package/build/dom/is-element.cjs +12 -25
- package/build/dom/is-element.cjs.map +1 -7
- package/build/dom/is-empty.cjs +23 -40
- package/build/dom/is-empty.cjs.map +1 -7
- package/build/dom/is-entirely-selected.cjs +71 -71
- package/build/dom/is-entirely-selected.cjs.map +1 -7
- package/build/dom/is-form-element.cjs +34 -34
- package/build/dom/is-form-element.cjs.map +1 -7
- package/build/dom/is-horizontal-edge.cjs +32 -29
- package/build/dom/is-horizontal-edge.cjs.map +1 -7
- package/build/dom/is-html-input-element.cjs +12 -25
- package/build/dom/is-html-input-element.cjs.map +1 -7
- package/build/dom/is-input-or-text-area.cjs +12 -25
- package/build/dom/is-input-or-text-area.cjs.map +1 -7
- package/build/dom/is-number-input.cjs +37 -34
- package/build/dom/is-number-input.cjs.map +1 -7
- package/build/dom/is-rtl.cjs +31 -29
- package/build/dom/is-rtl.cjs.map +1 -7
- package/build/dom/is-selection-forward.cjs +26 -39
- package/build/dom/is-selection-forward.cjs.map +1 -7
- package/build/dom/is-text-field.cjs +46 -44
- package/build/dom/is-text-field.cjs.map +1 -7
- package/build/dom/is-vertical-edge.cjs +32 -29
- package/build/dom/is-vertical-edge.cjs.map +1 -7
- package/build/dom/place-caret-at-edge.cjs +76 -79
- package/build/dom/place-caret-at-edge.cjs.map +1 -7
- package/build/dom/place-caret-at-horizontal-edge.cjs +30 -29
- package/build/dom/place-caret-at-horizontal-edge.cjs.map +1 -7
- package/build/dom/place-caret-at-vertical-edge.cjs +31 -29
- package/build/dom/place-caret-at-vertical-edge.cjs.map +1 -7
- package/build/dom/remove-invalid-html.cjs +36 -32
- package/build/dom/remove-invalid-html.cjs.map +1 -7
- package/build/dom/remove.cjs +15 -27
- package/build/dom/remove.cjs.map +1 -7
- package/build/dom/replace-tag.cjs +21 -32
- package/build/dom/replace-tag.cjs.map +1 -7
- package/build/dom/replace.cjs +35 -33
- package/build/dom/replace.cjs.map +1 -7
- package/build/dom/safe-html.cjs +46 -47
- package/build/dom/safe-html.cjs.map +1 -7
- package/build/dom/scroll-if-no-range.cjs +24 -37
- package/build/dom/scroll-if-no-range.cjs.map +1 -7
- package/build/dom/strip-html.cjs +34 -32
- package/build/dom/strip-html.cjs.map +1 -7
- package/build/dom/types.cjs +5 -0
- package/build/dom/unwrap.cjs +17 -31
- package/build/dom/unwrap.cjs.map +1 -7
- package/build/dom/wrap.cjs +17 -28
- package/build/dom/wrap.cjs.map +1 -7
- package/build/focusable.cjs +99 -77
- package/build/focusable.cjs.map +1 -7
- package/build/index.cjs +58 -39
- package/build/index.cjs.map +1 -7
- package/build/phrasing-content.cjs +163 -159
- package/build/phrasing-content.cjs.map +1 -7
- package/build/tabbable.cjs +123 -78
- package/build/tabbable.cjs.map +1 -7
- package/build/types.cjs +5 -0
- package/build/utils/assert-is-defined.cjs +8 -33
- package/build/utils/assert-is-defined.cjs.map +1 -7
- package/build-module/data-transfer.mjs +17 -15
- package/build-module/data-transfer.mjs.map +1 -7
- package/build-module/dom/caret-range-from-point.mjs +28 -19
- package/build-module/dom/caret-range-from-point.mjs.map +1 -7
- package/build-module/dom/clean-node-list.mjs +60 -105
- package/build-module/dom/clean-node-list.mjs.map +1 -7
- package/build-module/dom/compute-caret-rect.mjs +16 -12
- package/build-module/dom/compute-caret-rect.mjs.map +1 -7
- package/build-module/dom/document-has-selection.mjs +13 -6
- package/build-module/dom/document-has-selection.mjs.map +1 -7
- package/build-module/dom/document-has-text-selection.mjs +20 -10
- package/build-module/dom/document-has-text-selection.mjs.map +1 -7
- package/build-module/dom/document-has-uncollapsed-selection.mjs +14 -6
- package/build-module/dom/document-has-uncollapsed-selection.mjs.map +1 -7
- package/build-module/dom/get-computed-style.mjs +10 -10
- package/build-module/dom/get-computed-style.mjs.map +1 -7
- package/build-module/dom/get-offset-parent.mjs +21 -25
- package/build-module/dom/get-offset-parent.mjs.map +1 -7
- package/build-module/dom/get-range-height.mjs +15 -12
- package/build-module/dom/get-range-height.mjs.map +1 -7
- package/build-module/dom/get-rectangle-from-range.mjs +78 -113
- package/build-module/dom/get-rectangle-from-range.mjs.map +1 -7
- package/build-module/dom/get-scroll-container.mjs +28 -32
- package/build-module/dom/get-scroll-container.mjs.map +1 -7
- package/build-module/dom/hidden-caret-range-from-point.mjs +28 -19
- package/build-module/dom/hidden-caret-range-from-point.mjs.map +1 -7
- package/build-module/dom/index.mjs +28 -58
- package/build-module/dom/input-field-has-uncollapsed-selection.mjs +28 -23
- package/build-module/dom/input-field-has-uncollapsed-selection.mjs.map +1 -7
- package/build-module/dom/insert-after.mjs +13 -7
- package/build-module/dom/insert-after.mjs.map +1 -7
- package/build-module/dom/is-edge.mjs +53 -69
- package/build-module/dom/is-edge.mjs.map +1 -7
- package/build-module/dom/is-element.mjs +9 -6
- package/build-module/dom/is-element.mjs.map +1 -7
- package/build-module/dom/is-empty.mjs +20 -21
- package/build-module/dom/is-empty.mjs.map +1 -7
- package/build-module/dom/is-entirely-selected.mjs +51 -47
- package/build-module/dom/is-entirely-selected.mjs.map +1 -7
- package/build-module/dom/is-form-element.mjs +15 -11
- package/build-module/dom/is-form-element.mjs.map +1 -7
- package/build-module/dom/is-horizontal-edge.mjs +13 -6
- package/build-module/dom/is-horizontal-edge.mjs.map +1 -7
- package/build-module/dom/is-html-input-element.mjs +9 -6
- package/build-module/dom/is-html-input-element.mjs.map +1 -7
- package/build-module/dom/is-input-or-text-area.mjs +9 -6
- package/build-module/dom/is-input-or-text-area.mjs.map +1 -7
- package/build-module/dom/is-number-input.mjs +16 -10
- package/build-module/dom/is-number-input.mjs.map +1 -7
- package/build-module/dom/is-rtl.mjs +12 -6
- package/build-module/dom/is-rtl.mjs.map +1 -7
- package/build-module/dom/is-selection-forward.mjs +22 -19
- package/build-module/dom/is-selection-forward.mjs.map +1 -7
- package/build-module/dom/is-text-field.mjs +27 -21
- package/build-module/dom/is-text-field.mjs.map +1 -7
- package/build-module/dom/is-vertical-edge.mjs +13 -6
- package/build-module/dom/is-vertical-edge.mjs.map +1 -7
- package/build-module/dom/place-caret-at-edge.mjs +51 -52
- package/build-module/dom/place-caret-at-edge.mjs.map +1 -7
- package/build-module/dom/place-caret-at-horizontal-edge.mjs +11 -6
- package/build-module/dom/place-caret-at-horizontal-edge.mjs.map +1 -7
- package/build-module/dom/place-caret-at-vertical-edge.mjs +12 -6
- package/build-module/dom/place-caret-at-vertical-edge.mjs.map +1 -7
- package/build-module/dom/remove-invalid-html.mjs +17 -9
- package/build-module/dom/remove-invalid-html.mjs.map +1 -7
- package/build-module/dom/remove.mjs +11 -7
- package/build-module/dom/remove.mjs.map +1 -7
- package/build-module/dom/replace-tag.mjs +17 -12
- package/build-module/dom/replace-tag.mjs.map +1 -7
- package/build-module/dom/replace.mjs +13 -8
- package/build-module/dom/replace.mjs.map +1 -7
- package/build-module/dom/safe-html.mjs +27 -24
- package/build-module/dom/safe-html.mjs.map +1 -7
- package/build-module/dom/scroll-if-no-range.mjs +21 -14
- package/build-module/dom/scroll-if-no-range.mjs.map +1 -7
- package/build-module/dom/strip-html.mjs +15 -9
- package/build-module/dom/strip-html.mjs.map +1 -7
- package/build-module/dom/types.mjs +0 -0
- package/build-module/dom/unwrap.mjs +13 -11
- package/build-module/dom/unwrap.mjs.map +1 -7
- package/build-module/dom/wrap.mjs +13 -8
- package/build-module/dom/wrap.mjs.map +1 -7
- package/build-module/focusable.mjs +96 -54
- package/build-module/focusable.mjs.map +1 -7
- package/build-module/index.mjs +11 -5
- package/build-module/index.mjs.map +1 -7
- package/build-module/phrasing-content.mjs +158 -134
- package/build-module/phrasing-content.mjs.map +1 -7
- package/build-module/tabbable.mjs +117 -52
- package/build-module/tabbable.mjs.map +1 -7
- package/build-module/types.mjs +0 -0
- package/build-module/utils/assert-is-defined.mjs +4 -9
- package/build-module/utils/assert-is-defined.mjs.map +1 -7
- package/build-types/data-transfer.d.ts +2 -2
- package/build-types/data-transfer.d.ts.map +1 -1
- package/build-types/dom/caret-range-from-point.d.ts +4 -4
- package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
- package/build-types/dom/clean-node-list.d.ts +6 -46
- package/build-types/dom/clean-node-list.d.ts.map +1 -1
- package/build-types/dom/compute-caret-rect.d.ts +2 -2
- package/build-types/dom/compute-caret-rect.d.ts.map +1 -1
- package/build-types/dom/document-has-selection.d.ts +2 -2
- package/build-types/dom/document-has-selection.d.ts.map +1 -1
- package/build-types/dom/document-has-text-selection.d.ts +2 -2
- package/build-types/dom/document-has-text-selection.d.ts.map +1 -1
- package/build-types/dom/document-has-uncollapsed-selection.d.ts +2 -2
- package/build-types/dom/document-has-uncollapsed-selection.d.ts.map +1 -1
- package/build-types/dom/get-computed-style.d.ts +3 -3
- package/build-types/dom/get-computed-style.d.ts.map +1 -1
- package/build-types/dom/get-offset-parent.d.ts +2 -2
- package/build-types/dom/get-offset-parent.d.ts.map +1 -1
- package/build-types/dom/get-range-height.d.ts +2 -2
- package/build-types/dom/get-range-height.d.ts.map +1 -1
- package/build-types/dom/get-rectangle-from-range.d.ts +2 -2
- package/build-types/dom/get-rectangle-from-range.d.ts.map +1 -1
- package/build-types/dom/get-scroll-container.d.ts +5 -5
- package/build-types/dom/get-scroll-container.d.ts.map +1 -1
- package/build-types/dom/hidden-caret-range-from-point.d.ts +5 -5
- package/build-types/dom/hidden-caret-range-from-point.d.ts.map +1 -1
- package/build-types/dom/index.d.ts.map +1 -1
- package/build-types/dom/input-field-has-uncollapsed-selection.d.ts +2 -2
- package/build-types/dom/input-field-has-uncollapsed-selection.d.ts.map +1 -1
- package/build-types/dom/insert-after.d.ts +2 -3
- package/build-types/dom/insert-after.d.ts.map +1 -1
- package/build-types/dom/is-edge.d.ts +4 -4
- package/build-types/dom/is-edge.d.ts.map +1 -1
- package/build-types/dom/is-element.d.ts.map +1 -1
- package/build-types/dom/is-empty.d.ts +3 -3
- package/build-types/dom/is-empty.d.ts.map +1 -1
- package/build-types/dom/is-entirely-selected.d.ts +2 -2
- package/build-types/dom/is-entirely-selected.d.ts.map +1 -1
- package/build-types/dom/is-form-element.d.ts +3 -3
- package/build-types/dom/is-form-element.d.ts.map +1 -1
- package/build-types/dom/is-horizontal-edge.d.ts.map +1 -1
- package/build-types/dom/is-html-input-element.d.ts +1 -1
- package/build-types/dom/is-html-input-element.d.ts.map +1 -1
- package/build-types/dom/is-input-or-text-area.d.ts.map +1 -1
- package/build-types/dom/is-number-input.d.ts +2 -2
- package/build-types/dom/is-number-input.d.ts.map +1 -1
- package/build-types/dom/is-rtl.d.ts +2 -2
- package/build-types/dom/is-rtl.d.ts.map +1 -1
- package/build-types/dom/is-selection-forward.d.ts +2 -2
- package/build-types/dom/is-selection-forward.d.ts.map +1 -1
- package/build-types/dom/is-text-field.d.ts +2 -2
- package/build-types/dom/is-text-field.d.ts.map +1 -1
- package/build-types/dom/is-vertical-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-edge.d.ts +3 -3
- package/build-types/dom/place-caret-at-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
- package/build-types/dom/remove-invalid-html.d.ts +5 -4
- package/build-types/dom/remove-invalid-html.d.ts.map +1 -1
- package/build-types/dom/remove.d.ts +1 -2
- package/build-types/dom/remove.d.ts.map +1 -1
- package/build-types/dom/replace-tag.d.ts +3 -3
- package/build-types/dom/replace-tag.d.ts.map +1 -1
- package/build-types/dom/replace.d.ts +2 -3
- package/build-types/dom/replace.d.ts.map +1 -1
- package/build-types/dom/safe-html.d.ts +2 -2
- package/build-types/dom/safe-html.d.ts.map +1 -1
- package/build-types/dom/scroll-if-no-range.d.ts +5 -5
- package/build-types/dom/scroll-if-no-range.d.ts.map +1 -1
- package/build-types/dom/strip-html.d.ts +2 -2
- package/build-types/dom/strip-html.d.ts.map +1 -1
- package/build-types/dom/types.d.ts +32 -0
- package/build-types/dom/types.d.ts.map +1 -0
- package/build-types/dom/unwrap.d.ts +1 -3
- package/build-types/dom/unwrap.d.ts.map +1 -1
- package/build-types/dom/wrap.d.ts +2 -2
- package/build-types/dom/wrap.d.ts.map +1 -1
- package/build-types/focusable.d.ts +11 -30
- package/build-types/focusable.d.ts.map +1 -1
- package/build-types/index.d.ts +17 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/phrasing-content.d.ts +9 -24
- package/build-types/phrasing-content.d.ts.map +1 -1
- package/build-types/tabbable.d.ts +10 -15
- package/build-types/tabbable.d.ts.map +1 -1
- package/build-types/types.d.ts +29 -0
- package/build-types/types.d.ts.map +1 -0
- package/package.json +6 -7
- package/src/{data-transfer.js → data-transfer.ts} +3 -3
- package/src/dom/{caret-range-from-point.js → caret-range-from-point.ts} +9 -5
- package/src/dom/{clean-node-list.js → clean-node-list.ts} +16 -24
- package/src/dom/{compute-caret-rect.js → compute-caret-rect.ts} +3 -3
- package/src/dom/{document-has-selection.js → document-has-selection.ts} +3 -3
- package/src/dom/{document-has-text-selection.js → document-has-text-selection.ts} +3 -3
- package/src/dom/{document-has-uncollapsed-selection.js → document-has-uncollapsed-selection.ts} +5 -3
- package/src/dom/{get-computed-style.js → get-computed-style.ts} +5 -3
- package/src/dom/{get-offset-parent.js → get-offset-parent.ts} +9 -14
- package/src/dom/{get-range-height.js → get-range-height.ts} +3 -3
- package/src/dom/{get-rectangle-from-range.js → get-rectangle-from-range.ts} +6 -12
- package/src/dom/{get-scroll-container.js → get-scroll-container.ts} +9 -9
- package/src/dom/{hidden-caret-range-from-point.js → hidden-caret-range-from-point.ts} +11 -6
- package/src/dom/{input-field-has-uncollapsed-selection.js → input-field-has-uncollapsed-selection.ts} +7 -5
- package/src/dom/{insert-after.js → insert-after.ts} +6 -4
- package/src/dom/{is-edge.js → is-edge.ts} +44 -48
- package/src/dom/{is-element.js → is-element.ts} +3 -1
- package/src/dom/{is-empty.js → is-empty.ts} +5 -7
- package/src/dom/{is-entirely-selected.js → is-entirely-selected.ts} +14 -11
- package/src/dom/{is-form-element.js → is-form-element.ts} +5 -3
- package/src/dom/{is-horizontal-edge.js → is-horizontal-edge.ts} +4 -1
- package/src/dom/{is-html-input-element.js → is-html-input-element.ts} +3 -1
- package/src/dom/{is-input-or-text-area.js → is-input-or-text-area.ts} +3 -1
- package/src/dom/{is-number-input.js → is-number-input.ts} +3 -3
- package/src/dom/{is-rtl.js → is-rtl.ts} +3 -3
- package/src/dom/{is-selection-forward.js → is-selection-forward.ts} +3 -3
- package/src/dom/{is-text-field.js → is-text-field.ts} +4 -4
- package/src/dom/{is-vertical-edge.js → is-vertical-edge.ts} +4 -1
- package/src/dom/{place-caret-at-edge.js → place-caret-at-edge.ts} +17 -9
- package/src/dom/{place-caret-at-horizontal-edge.js → place-caret-at-horizontal-edge.ts} +4 -1
- package/src/dom/{place-caret-at-vertical-edge.js → place-caret-at-vertical-edge.ts} +5 -1
- package/src/dom/{remove-invalid-html.js → remove-invalid-html.ts} +9 -4
- package/src/dom/{remove.js → remove.ts} +2 -3
- package/src/dom/{replace-tag.js → replace-tag.ts} +4 -4
- package/src/dom/{replace.js → replace.ts} +6 -4
- package/src/dom/{safe-html.js → safe-html.ts} +3 -3
- package/src/dom/{scroll-if-no-range.js → scroll-if-no-range.ts} +9 -5
- package/src/dom/{strip-html.js → strip-html.ts} +3 -3
- package/src/dom/test/{get-rectangle-from-range.browser.test.js → get-rectangle-from-range.browser.test.ts} +25 -25
- package/src/dom/types.ts +28 -0
- package/src/dom/{unwrap.js → unwrap.ts} +2 -4
- package/src/dom/{wrap.js → wrap.ts} +3 -3
- package/src/{focusable.js → focusable.ts} +34 -32
- package/src/index.ts +33 -0
- package/src/{phrasing-content.js → phrasing-content.ts} +15 -30
- package/src/{tabbable.js → tabbable.ts} +48 -39
- package/src/test/{dom.jsdom.test.js → dom.jsdom.test.ts} +30 -6
- package/src/test/{focusable.browser.test.js → focusable.browser.test.ts} +14 -13
- package/src/test/{tabbable.browser.test.js → tabbable.browser.test.ts} +3 -2
- package/src/types.ts +32 -0
- package/CHANGELOG.md +0 -317
- package/build/dom/index.cjs.map +0 -7
- package/build-module/dom/index.mjs.map +0 -7
- package/src/index.js +0 -12
- /package/src/dom/{index.js → index.ts} +0 -0
- /package/src/dom/test/{safe-html.jsdom.test.js → safe-html.jsdom.test.ts} +0 -0
- /package/src/dom/test/{strip-html.jsdom.test.js → strip-html.jsdom.test.ts} +0 -0
- /package/src/test/{focusable-area.jsdom.test.js → focusable-area.jsdom.test.ts} +0 -0
- /package/src/test/{utils.js → utils.ts} +0 -0
|
@@ -1,172 +1,176 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/dom/src/phrasing-content.js
|
|
21
|
-
var phrasing_content_exports = {};
|
|
22
|
-
__export(phrasing_content_exports, {
|
|
23
|
-
getPhrasingContentSchema: () => getPhrasingContentSchema,
|
|
24
|
-
isPhrasingContent: () => isPhrasingContent,
|
|
25
|
-
isTextContent: () => isTextContent
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
26
5
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
6
|
+
// packages/dom/src/phrasing-content.ts
|
|
7
|
+
/**
|
|
8
|
+
* All phrasing content elements.
|
|
9
|
+
*
|
|
10
|
+
* @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* All text-level semantic elements.
|
|
14
|
+
*
|
|
15
|
+
* @see https://html.spec.whatwg.org/multipage/text-level-semantics.html
|
|
16
|
+
*/
|
|
17
|
+
const textContentSchema = {
|
|
18
|
+
strong: {},
|
|
19
|
+
em: {},
|
|
20
|
+
s: {},
|
|
21
|
+
del: {},
|
|
22
|
+
ins: {},
|
|
23
|
+
a: { attributes: [
|
|
24
|
+
"href",
|
|
25
|
+
"target",
|
|
26
|
+
"rel",
|
|
27
|
+
"id"
|
|
28
|
+
] },
|
|
29
|
+
code: {},
|
|
30
|
+
abbr: { attributes: ["title"] },
|
|
31
|
+
sub: {},
|
|
32
|
+
sup: {},
|
|
33
|
+
br: {},
|
|
34
|
+
small: {},
|
|
35
|
+
q: { attributes: ["cite"] },
|
|
36
|
+
dfn: { attributes: ["title"] },
|
|
37
|
+
data: { attributes: ["value"] },
|
|
38
|
+
time: { attributes: ["datetime"] },
|
|
39
|
+
var: {},
|
|
40
|
+
samp: {},
|
|
41
|
+
kbd: {},
|
|
42
|
+
i: {},
|
|
43
|
+
b: {},
|
|
44
|
+
u: {},
|
|
45
|
+
mark: {},
|
|
46
|
+
ruby: {},
|
|
47
|
+
rt: {},
|
|
48
|
+
rp: {},
|
|
49
|
+
bdi: { attributes: ["dir"] },
|
|
50
|
+
bdo: { attributes: ["dir"] },
|
|
51
|
+
wbr: {},
|
|
52
|
+
"#text": {}
|
|
61
53
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Embedded content elements.
|
|
56
|
+
*
|
|
57
|
+
* @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0
|
|
58
|
+
*/
|
|
59
|
+
const embeddedContentSchema = {
|
|
60
|
+
audio: { attributes: [
|
|
61
|
+
"src",
|
|
62
|
+
"preload",
|
|
63
|
+
"autoplay",
|
|
64
|
+
"mediagroup",
|
|
65
|
+
"loop",
|
|
66
|
+
"muted"
|
|
67
|
+
] },
|
|
68
|
+
canvas: { attributes: ["width", "height"] },
|
|
69
|
+
embed: { attributes: [
|
|
70
|
+
"src",
|
|
71
|
+
"type",
|
|
72
|
+
"width",
|
|
73
|
+
"height"
|
|
74
|
+
] },
|
|
75
|
+
img: { attributes: [
|
|
76
|
+
"alt",
|
|
77
|
+
"src",
|
|
78
|
+
"srcset",
|
|
79
|
+
"usemap",
|
|
80
|
+
"ismap",
|
|
81
|
+
"width",
|
|
82
|
+
"height"
|
|
83
|
+
] },
|
|
84
|
+
object: { attributes: [
|
|
85
|
+
"data",
|
|
86
|
+
"type",
|
|
87
|
+
"name",
|
|
88
|
+
"usemap",
|
|
89
|
+
"form",
|
|
90
|
+
"width",
|
|
91
|
+
"height"
|
|
92
|
+
] },
|
|
93
|
+
video: { attributes: [
|
|
94
|
+
"src",
|
|
95
|
+
"poster",
|
|
96
|
+
"preload",
|
|
97
|
+
"playsinline",
|
|
98
|
+
"autoplay",
|
|
99
|
+
"mediagroup",
|
|
100
|
+
"loop",
|
|
101
|
+
"muted",
|
|
102
|
+
"controls",
|
|
103
|
+
"width",
|
|
104
|
+
"height"
|
|
105
|
+
] },
|
|
106
|
+
math: {
|
|
107
|
+
attributes: ["display", "xmlns"],
|
|
108
|
+
children: "*"
|
|
109
|
+
}
|
|
116
110
|
};
|
|
117
|
-
|
|
111
|
+
const excludedElements = [
|
|
112
|
+
"#text",
|
|
113
|
+
"br",
|
|
114
|
+
"wbr"
|
|
115
|
+
];
|
|
118
116
|
Object.keys(textContentSchema).filter((element) => !excludedElements.includes(element)).forEach((tag) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
const { [tag]: removedTag, ...restSchema } = textContentSchema;
|
|
118
|
+
textContentSchema[tag].children = {
|
|
119
|
+
...restSchema,
|
|
120
|
+
img: embeddedContentSchema.img
|
|
121
|
+
};
|
|
124
122
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Phrasing content elements.
|
|
125
|
+
*
|
|
126
|
+
* @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
|
|
127
|
+
*/
|
|
128
|
+
const phrasingContentSchema = {
|
|
129
|
+
...textContentSchema,
|
|
130
|
+
...embeddedContentSchema
|
|
128
131
|
};
|
|
132
|
+
/**
|
|
133
|
+
* Get schema of possible paths for phrasing content.
|
|
134
|
+
*
|
|
135
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
|
|
136
|
+
*
|
|
137
|
+
* @param [context] Set to "paste" to exclude invisible elements and
|
|
138
|
+
* sensitive data.
|
|
139
|
+
*
|
|
140
|
+
* @return Schema.
|
|
141
|
+
*/
|
|
129
142
|
function getPhrasingContentSchema(context) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// Invisible.
|
|
138
|
-
data,
|
|
139
|
-
// Invisible.
|
|
140
|
-
time,
|
|
141
|
-
// Invisible.
|
|
142
|
-
wbr,
|
|
143
|
-
// Invisible.
|
|
144
|
-
bdi,
|
|
145
|
-
// Invisible.
|
|
146
|
-
bdo,
|
|
147
|
-
// Invisible.
|
|
148
|
-
...remainingContentSchema
|
|
149
|
-
} = {
|
|
150
|
-
...phrasingContentSchema,
|
|
151
|
-
// We shouldn't paste potentially sensitive information which is not
|
|
152
|
-
// visible to the user when pasted, so strip the attributes.
|
|
153
|
-
ins: { children: phrasingContentSchema.ins.children },
|
|
154
|
-
del: { children: phrasingContentSchema.del.children }
|
|
155
|
-
};
|
|
156
|
-
return remainingContentSchema;
|
|
143
|
+
if (context !== "paste") return phrasingContentSchema;
|
|
144
|
+
const { u, abbr, data, time, wbr, bdi, bdo, ...remainingContentSchema } = {
|
|
145
|
+
...phrasingContentSchema,
|
|
146
|
+
ins: { children: phrasingContentSchema.ins.children },
|
|
147
|
+
del: { children: phrasingContentSchema.del.children }
|
|
148
|
+
};
|
|
149
|
+
return remainingContentSchema;
|
|
157
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Find out whether or not the given node is phrasing content.
|
|
153
|
+
*
|
|
154
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
|
|
155
|
+
*
|
|
156
|
+
* @param node The node to test.
|
|
157
|
+
*
|
|
158
|
+
* @return True if phrasing content, false if not.
|
|
159
|
+
*/
|
|
158
160
|
function isPhrasingContent(node) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
+
const tag = node.nodeName.toLowerCase();
|
|
162
|
+
return getPhrasingContentSchema().hasOwnProperty(tag) || tag === "span";
|
|
161
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* @param node
|
|
166
|
+
* @return Node is text content
|
|
167
|
+
*/
|
|
162
168
|
function isTextContent(node) {
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
const tag = node.nodeName.toLowerCase();
|
|
170
|
+
return textContentSchema.hasOwnProperty(tag) || tag === "span";
|
|
165
171
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
});
|
|
172
|
-
//# sourceMappingURL=phrasing-content.cjs.map
|
|
172
|
+
exports.getPhrasingContentSchema = getPhrasingContentSchema;
|
|
173
|
+
exports.isPhrasingContent = isPhrasingContent;
|
|
174
|
+
exports.isTextContent = isTextContent;
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=phrasing-content.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/phrasing-content.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * All phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\n\n/**\n * @typedef {Record<string,SemanticElementDefinition>} ContentSchema\n */\n\n/**\n * @typedef SemanticElementDefinition\n * @property {string[]} [attributes] Content attributes\n * @property {ContentSchema|'*'} [children] Content attributes\n */\n\n/**\n * All text-level semantic elements.\n *\n * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html\n *\n * @type {ContentSchema}\n */\nconst textContentSchema = {\n\tstrong: {},\n\tem: {},\n\ts: {},\n\tdel: {},\n\tins: {},\n\ta: { attributes: [ 'href', 'target', 'rel', 'id' ] },\n\tcode: {},\n\tabbr: { attributes: [ 'title' ] },\n\tsub: {},\n\tsup: {},\n\tbr: {},\n\tsmall: {},\n\t// To do: fix blockquote.\n\t// cite: {},\n\tq: { attributes: [ 'cite' ] },\n\tdfn: { attributes: [ 'title' ] },\n\tdata: { attributes: [ 'value' ] },\n\ttime: { attributes: [ 'datetime' ] },\n\tvar: {},\n\tsamp: {},\n\tkbd: {},\n\ti: {},\n\tb: {},\n\tu: {},\n\tmark: {},\n\truby: {},\n\trt: {},\n\trp: {},\n\tbdi: { attributes: [ 'dir' ] },\n\tbdo: { attributes: [ 'dir' ] },\n\twbr: {},\n\t'#text': {},\n};\n\n/**\n * Embedded content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0\n *\n * @type {ContentSchema}\n */\nconst embeddedContentSchema = {\n\taudio: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t],\n\t},\n\tcanvas: { attributes: [ 'width', 'height' ] },\n\tembed: { attributes: [ 'src', 'type', 'width', 'height' ] },\n\timg: {\n\t\tattributes: [\n\t\t\t'alt',\n\t\t\t'src',\n\t\t\t'srcset',\n\t\t\t'usemap',\n\t\t\t'ismap',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tobject: {\n\t\tattributes: [\n\t\t\t'data',\n\t\t\t'type',\n\t\t\t'name',\n\t\t\t'usemap',\n\t\t\t'form',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tvideo: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'poster',\n\t\t\t'preload',\n\t\t\t'playsinline',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t\t'controls',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tmath: {\n\t\tattributes: [ 'display', 'xmlns' ],\n\t\tchildren: '*',\n\t},\n};\n\nconst excludedElements = [ '#text', 'br', 'wbr' ];\n\n// Wire up children for each text-level wrapper.\n// - Recursion is needed (e.g. strong > em > strong; not strong > strong).\n// - <img> is allowed too: text-level wrappers accept phrasing content, and\n// <a>'s transparent model permits non-interactive embedded content.\nObject.keys( textContentSchema )\n\t.filter( ( element ) => ! excludedElements.includes( element ) )\n\t.forEach( ( tag ) => {\n\t\tconst { [ tag ]: removedTag, ...restSchema } = textContentSchema;\n\t\ttextContentSchema[ tag ].children = {\n\t\t\t...restSchema,\n\t\t\timg: embeddedContentSchema.img,\n\t\t};\n\t} );\n\n/**\n * Phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\nconst phrasingContentSchema = {\n\t...textContentSchema,\n\t...embeddedContentSchema,\n};\n\n/**\n * Get schema of possible paths for phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {string} [context] Set to \"paste\" to exclude invisible elements and\n * sensitive data.\n *\n * @return {Partial<ContentSchema>} Schema.\n */\nexport function getPhrasingContentSchema( context ) {\n\tif ( context !== 'paste' ) {\n\t\treturn phrasingContentSchema;\n\t}\n\n\t/**\n\t * @type {Partial<ContentSchema>}\n\t */\n\tconst {\n\t\tu, // Used to mark misspelling. Shouldn't be pasted.\n\t\tabbr, // Invisible.\n\t\tdata, // Invisible.\n\t\ttime, // Invisible.\n\t\twbr, // Invisible.\n\t\tbdi, // Invisible.\n\t\tbdo, // Invisible.\n\t\t...remainingContentSchema\n\t} = {\n\t\t...phrasingContentSchema,\n\t\t// We shouldn't paste potentially sensitive information which is not\n\t\t// visible to the user when pasted, so strip the attributes.\n\t\tins: { children: phrasingContentSchema.ins.children },\n\t\tdel: { children: phrasingContentSchema.del.children },\n\t};\n\n\treturn remainingContentSchema;\n}\n\n/**\n * Find out whether or not the given node is phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {Node} node The node to test.\n *\n * @return {boolean} True if phrasing content, false if not.\n */\nexport function isPhrasingContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';\n}\n\n/**\n * @param {Node} node\n * @return {boolean} Node is text content\n */\nexport function isTextContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn textContentSchema.hasOwnProperty( tag ) || tag === 'span';\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,IAAM,oBAAoB;AAAA,EACzB,QAAQ,CAAC;AAAA,EACT,IAAI,CAAC;AAAA,EACL,GAAG,CAAC;AAAA,EACJ,KAAK,CAAC;AAAA,EACN,KAAK,CAAC;AAAA,EACN,GAAG,EAAE,YAAY,CAAE,QAAQ,UAAU,OAAO,IAAK,EAAE;AAAA,EACnD,MAAM,CAAC;AAAA,EACP,MAAM,EAAE,YAAY,CAAE,OAAQ,EAAE;AAAA,EAChC,KAAK,CAAC;AAAA,EACN,KAAK,CAAC;AAAA,EACN,IAAI,CAAC;AAAA,EACL,OAAO,CAAC;AAAA;AAAA;AAAA,EAGR,GAAG,EAAE,YAAY,CAAE,MAAO,EAAE;AAAA,EAC5B,KAAK,EAAE,YAAY,CAAE,OAAQ,EAAE;AAAA,EAC/B,MAAM,EAAE,YAAY,CAAE,OAAQ,EAAE;AAAA,EAChC,MAAM,EAAE,YAAY,CAAE,UAAW,EAAE;AAAA,EACnC,KAAK,CAAC;AAAA,EACN,MAAM,CAAC;AAAA,EACP,KAAK,CAAC;AAAA,EACN,GAAG,CAAC;AAAA,EACJ,GAAG,CAAC;AAAA,EACJ,GAAG,CAAC;AAAA,EACJ,MAAM,CAAC;AAAA,EACP,MAAM,CAAC;AAAA,EACP,IAAI,CAAC;AAAA,EACL,IAAI,CAAC;AAAA,EACL,KAAK,EAAE,YAAY,CAAE,KAAM,EAAE;AAAA,EAC7B,KAAK,EAAE,YAAY,CAAE,KAAM,EAAE;AAAA,EAC7B,KAAK,CAAC;AAAA,EACN,SAAS,CAAC;AACX;AASA,IAAM,wBAAwB;AAAA,EAC7B,OAAO;AAAA,IACN,YAAY;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EACA,QAAQ,EAAE,YAAY,CAAE,SAAS,QAAS,EAAE;AAAA,EAC5C,OAAO,EAAE,YAAY,CAAE,OAAO,QAAQ,SAAS,QAAS,EAAE;AAAA,EAC1D,KAAK;AAAA,IACJ,YAAY;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EACA,QAAQ;AAAA,IACP,YAAY;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EACA,OAAO;AAAA,IACN,YAAY;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EACA,MAAM;AAAA,IACL,YAAY,CAAE,WAAW,OAAQ;AAAA,IACjC,UAAU;AAAA,EACX;AACD;AAEA,IAAM,mBAAmB,CAAE,SAAS,MAAM,KAAM;AAMhD,OAAO,KAAM,iBAAkB,EAC7B,OAAQ,CAAE,YAAa,CAAE,iBAAiB,SAAU,OAAQ,CAAE,EAC9D,QAAS,CAAE,QAAS;AACpB,QAAM,EAAE,CAAE,GAAI,GAAG,YAAY,GAAG,WAAW,IAAI;AAC/C,oBAAmB,GAAI,EAAE,WAAW;AAAA,IACnC,GAAG;AAAA,IACH,KAAK,sBAAsB;AAAA,EAC5B;AACD,CAAE;AAOH,IAAM,wBAAwB;AAAA,EAC7B,GAAG;AAAA,EACH,GAAG;AACJ;AAYO,SAAS,yBAA0B,SAAU;AACnD,MAAK,YAAY,SAAU;AAC1B,WAAO;AAAA,EACR;AAKA,QAAM;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA,GAAG;AAAA,EACJ,IAAI;AAAA,IACH,GAAG;AAAA;AAAA;AAAA,IAGH,KAAK,EAAE,UAAU,sBAAsB,IAAI,SAAS;AAAA,IACpD,KAAK,EAAE,UAAU,sBAAsB,IAAI,SAAS;AAAA,EACrD;AAEA,SAAO;AACR;AAWO,SAAS,kBAAmB,MAAO;AACzC,QAAM,MAAM,KAAK,SAAS,YAAY;AACtC,SAAO,yBAAyB,EAAE,eAAgB,GAAI,KAAK,QAAQ;AACpE;AAMO,SAAS,cAAe,MAAO;AACrC,QAAM,MAAM,KAAK,SAAS,YAAY;AACtC,SAAO,kBAAkB,eAAgB,GAAI,KAAK,QAAQ;AAC3D;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"phrasing-content.cjs","names":[],"sources":["../src/phrasing-content.ts"],"sourcesContent":["import type { ContentSchema } from './types';\n\n/**\n * All phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\n\n/**\n * All text-level semantic elements.\n *\n * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html\n */\nconst textContentSchema: ContentSchema = {\n\tstrong: {},\n\tem: {},\n\ts: {},\n\tdel: {},\n\tins: {},\n\ta: { attributes: [ 'href', 'target', 'rel', 'id' ] },\n\tcode: {},\n\tabbr: { attributes: [ 'title' ] },\n\tsub: {},\n\tsup: {},\n\tbr: {},\n\tsmall: {},\n\t// To do: fix blockquote.\n\t// cite: {},\n\tq: { attributes: [ 'cite' ] },\n\tdfn: { attributes: [ 'title' ] },\n\tdata: { attributes: [ 'value' ] },\n\ttime: { attributes: [ 'datetime' ] },\n\tvar: {},\n\tsamp: {},\n\tkbd: {},\n\ti: {},\n\tb: {},\n\tu: {},\n\tmark: {},\n\truby: {},\n\trt: {},\n\trp: {},\n\tbdi: { attributes: [ 'dir' ] },\n\tbdo: { attributes: [ 'dir' ] },\n\twbr: {},\n\t'#text': {},\n};\n\n/**\n * Embedded content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0\n */\nconst embeddedContentSchema: ContentSchema = {\n\taudio: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t],\n\t},\n\tcanvas: { attributes: [ 'width', 'height' ] },\n\tembed: { attributes: [ 'src', 'type', 'width', 'height' ] },\n\timg: {\n\t\tattributes: [\n\t\t\t'alt',\n\t\t\t'src',\n\t\t\t'srcset',\n\t\t\t'usemap',\n\t\t\t'ismap',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tobject: {\n\t\tattributes: [\n\t\t\t'data',\n\t\t\t'type',\n\t\t\t'name',\n\t\t\t'usemap',\n\t\t\t'form',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tvideo: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'poster',\n\t\t\t'preload',\n\t\t\t'playsinline',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t\t'controls',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tmath: {\n\t\tattributes: [ 'display', 'xmlns' ],\n\t\tchildren: '*',\n\t},\n};\n\nconst excludedElements = [ '#text', 'br', 'wbr' ];\n\n// Wire up children for each text-level wrapper.\n// - Recursion is needed (e.g. strong > em > strong; not strong > strong).\n// - <img> is allowed too: text-level wrappers accept phrasing content, and\n// <a>'s transparent model permits non-interactive embedded content.\nObject.keys( textContentSchema )\n\t.filter( ( element ) => ! excludedElements.includes( element ) )\n\t.forEach( ( tag ) => {\n\t\tconst { [ tag ]: removedTag, ...restSchema } = textContentSchema;\n\t\ttextContentSchema[ tag ].children = {\n\t\t\t...restSchema,\n\t\t\timg: embeddedContentSchema.img,\n\t\t};\n\t} );\n\n/**\n * Phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\nconst phrasingContentSchema = {\n\t...textContentSchema,\n\t...embeddedContentSchema,\n};\n\n/**\n * Get schema of possible paths for phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param [context] Set to \"paste\" to exclude invisible elements and\n * sensitive data.\n *\n * @return Schema.\n */\nexport function getPhrasingContentSchema( context?: string ): ContentSchema {\n\tif ( context !== 'paste' ) {\n\t\treturn phrasingContentSchema;\n\t}\n\n\tconst {\n\t\tu, // Used to mark misspelling. Shouldn't be pasted.\n\t\tabbr, // Invisible.\n\t\tdata, // Invisible.\n\t\ttime, // Invisible.\n\t\twbr, // Invisible.\n\t\tbdi, // Invisible.\n\t\tbdo, // Invisible.\n\t\t...remainingContentSchema\n\t}: ContentSchema = {\n\t\t...phrasingContentSchema,\n\t\t// We shouldn't paste potentially sensitive information which is not\n\t\t// visible to the user when pasted, so strip the attributes.\n\t\tins: { children: phrasingContentSchema.ins.children },\n\t\tdel: { children: phrasingContentSchema.del.children },\n\t};\n\n\treturn remainingContentSchema;\n}\n\n/**\n * Find out whether or not the given node is phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param node The node to test.\n *\n * @return True if phrasing content, false if not.\n */\nexport function isPhrasingContent( node: Node ): boolean {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';\n}\n\n/**\n * @param node\n * @return Node is text content\n */\nexport function isTextContent( node: Node ): boolean {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn textContentSchema.hasOwnProperty( tag ) || tag === 'span';\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,MAAM,oBAAmC;CACxC,QAAQ,CAAC;CACT,IAAI,CAAC;CACL,GAAG,CAAC;CACJ,KAAK,CAAC;CACN,KAAK,CAAC;CACN,GAAG,EAAE,YAAY;EAAE;EAAQ;EAAU;EAAO;CAAK,EAAE;CACnD,MAAM,CAAC;CACP,MAAM,EAAE,YAAY,CAAE,OAAQ,EAAE;CAChC,KAAK,CAAC;CACN,KAAK,CAAC;CACN,IAAI,CAAC;CACL,OAAO,CAAC;CAGR,GAAG,EAAE,YAAY,CAAE,MAAO,EAAE;CAC5B,KAAK,EAAE,YAAY,CAAE,OAAQ,EAAE;CAC/B,MAAM,EAAE,YAAY,CAAE,OAAQ,EAAE;CAChC,MAAM,EAAE,YAAY,CAAE,UAAW,EAAE;CACnC,KAAK,CAAC;CACN,MAAM,CAAC;CACP,KAAK,CAAC;CACN,GAAG,CAAC;CACJ,GAAG,CAAC;CACJ,GAAG,CAAC;CACJ,MAAM,CAAC;CACP,MAAM,CAAC;CACP,IAAI,CAAC;CACL,IAAI,CAAC;CACL,KAAK,EAAE,YAAY,CAAE,KAAM,EAAE;CAC7B,KAAK,EAAE,YAAY,CAAE,KAAM,EAAE;CAC7B,KAAK,CAAC;CACN,SAAS,CAAC;AACX;;;;;;AAOA,MAAM,wBAAuC;CAC5C,OAAO,EACN,YAAY;EACX;EACA;EACA;EACA;EACA;EACA;CACD,EACD;CACA,QAAQ,EAAE,YAAY,CAAE,SAAS,QAAS,EAAE;CAC5C,OAAO,EAAE,YAAY;EAAE;EAAO;EAAQ;EAAS;CAAS,EAAE;CAC1D,KAAK,EACJ,YAAY;EACX;EACA;EACA;EACA;EACA;EACA;EACA;CACD,EACD;CACA,QAAQ,EACP,YAAY;EACX;EACA;EACA;EACA;EACA;EACA;EACA;CACD,EACD;CACA,OAAO,EACN,YAAY;EACX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,EACD;CACA,MAAM;EACL,YAAY,CAAE,WAAW,OAAQ;EACjC,UAAU;CACX;AACD;AAEA,MAAM,mBAAmB;CAAE;CAAS;CAAM;AAAM;AAMhD,OAAO,KAAM,iBAAkB,CAAC,CAC9B,QAAU,YAAa,CAAE,iBAAiB,SAAU,OAAQ,CAAE,CAAC,CAC/D,SAAW,QAAS;CACpB,MAAM,GAAI,MAAO,YAAY,GAAG,eAAe;CAC/C,kBAAmB,IAAK,CAAC,WAAW;EACnC,GAAG;EACH,KAAK,sBAAsB;CAC5B;AACD,CAAE;;;;;;AAOH,MAAM,wBAAwB;CAC7B,GAAG;CACH,GAAG;AACJ;;;;;;;;;;;AAYA,SAAgB,yBAA0B,SAAkC;CAC3E,IAAK,YAAY,SAChB,OAAO;CAGR,MAAM,EACL,GACA,MACA,MACA,MACA,KACA,KACA,KACA,GAAG,2BACe;EAClB,GAAG;EAGH,KAAK,EAAE,UAAU,sBAAsB,IAAI,SAAS;EACpD,KAAK,EAAE,UAAU,sBAAsB,IAAI,SAAS;CACrD;CAEA,OAAO;AACR;;;;;;;;;;AAWA,SAAgB,kBAAmB,MAAsB;CACxD,MAAM,MAAM,KAAK,SAAS,YAAY;CACtC,OAAO,yBAAyB,CAAC,CAAC,eAAgB,GAAI,KAAK,QAAQ;AACpE;;;;;AAMA,SAAgB,cAAe,MAAsB;CACpD,MAAM,MAAM,KAAK,SAAS,YAAY;CACtC,OAAO,kBAAkB,eAAgB,GAAI,KAAK,QAAQ;AAC3D"}
|
package/build/tabbable.cjs
CHANGED
|
@@ -1,100 +1,145 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/dom/src/tabbable.js
|
|
21
|
-
var tabbable_exports = {};
|
|
22
|
-
__export(tabbable_exports, {
|
|
23
|
-
find: () => find,
|
|
24
|
-
findNext: () => findNext,
|
|
25
|
-
findPrevious: () => findPrevious,
|
|
26
|
-
isTabbableIndex: () => isTabbableIndex
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
27
5
|
});
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
let __focusable_ts = require("./focusable.cjs");
|
|
7
|
+
// packages/dom/src/tabbable.ts
|
|
8
|
+
/**
|
|
9
|
+
* Returns the tab index of the given element. In contrast with the tabIndex
|
|
10
|
+
* property, this normalizes the default (0) to avoid browser inconsistencies,
|
|
11
|
+
* operating under the assumption that this function is only ever called with a
|
|
12
|
+
* focusable node.
|
|
13
|
+
*
|
|
14
|
+
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261
|
|
15
|
+
*
|
|
16
|
+
* @param element Element from which to retrieve.
|
|
17
|
+
*
|
|
18
|
+
* @return Tab index of element (default 0).
|
|
19
|
+
*/
|
|
30
20
|
function getTabIndex(element) {
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
const tabIndex = element.getAttribute("tabindex");
|
|
22
|
+
return tabIndex === null ? 0 : parseInt(tabIndex, 10);
|
|
33
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns true if the specified element is tabbable, or false otherwise.
|
|
26
|
+
*
|
|
27
|
+
* @param element Element to test.
|
|
28
|
+
*
|
|
29
|
+
* @return Whether element is tabbable.
|
|
30
|
+
*/
|
|
34
31
|
function isTabbableIndex(element) {
|
|
35
|
-
|
|
32
|
+
return getTabIndex(element) !== -1;
|
|
36
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns a stateful reducer function which constructs a filtered array of
|
|
36
|
+
* tabbable elements, where at most one radio input is selected for a given
|
|
37
|
+
* name, giving priority to checked input, falling back to the first
|
|
38
|
+
* encountered.
|
|
39
|
+
*
|
|
40
|
+
* @return Radio group collapse reducer.
|
|
41
|
+
*/
|
|
37
42
|
function createStatefulCollapseRadioGroup() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
result = result.filter((e) => e !== hadChosenElement);
|
|
52
|
-
}
|
|
53
|
-
CHOSEN_RADIO_BY_NAME[name] = element;
|
|
54
|
-
return result.concat(element);
|
|
55
|
-
};
|
|
43
|
+
const CHOSEN_RADIO_BY_NAME = {};
|
|
44
|
+
return function collapseRadioGroup(result, element) {
|
|
45
|
+
const { nodeName, type, checked, name } = element;
|
|
46
|
+
if (nodeName !== "INPUT" || type !== "radio" || !name) return result.concat(element);
|
|
47
|
+
const hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name);
|
|
48
|
+
if (!(checked || !hasChosen)) return result;
|
|
49
|
+
if (hasChosen) {
|
|
50
|
+
const hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
|
|
51
|
+
result = result.filter((e) => e !== hadChosenElement);
|
|
52
|
+
}
|
|
53
|
+
CHOSEN_RADIO_BY_NAME[name] = element;
|
|
54
|
+
return result.concat(element);
|
|
55
|
+
};
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* An array map callback, returning an object with the element value and its
|
|
59
|
+
* array index location as properties. This is used to emulate a proper stable
|
|
60
|
+
* sort where equal tabIndex should be left in order of their occurrence in the
|
|
61
|
+
* document.
|
|
62
|
+
*
|
|
63
|
+
* @param element Element.
|
|
64
|
+
* @param index Array index of element.
|
|
65
|
+
*
|
|
66
|
+
* @return Mapped object with element, index.
|
|
67
|
+
*/
|
|
57
68
|
function mapElementToObjectTabbable(element, index) {
|
|
58
|
-
|
|
69
|
+
return {
|
|
70
|
+
element,
|
|
71
|
+
index
|
|
72
|
+
};
|
|
59
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* An array map callback, returning an element of the given mapped object's
|
|
76
|
+
* element value.
|
|
77
|
+
*
|
|
78
|
+
* @param object Mapped object with element.
|
|
79
|
+
*
|
|
80
|
+
* @return Mapped object element.
|
|
81
|
+
*/
|
|
60
82
|
function mapObjectTabbableToElement(object) {
|
|
61
|
-
|
|
83
|
+
return object.element;
|
|
62
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* A sort comparator function used in comparing two objects of mapped elements.
|
|
87
|
+
*
|
|
88
|
+
* @see mapElementToObjectTabbable
|
|
89
|
+
*
|
|
90
|
+
* @param a First object to compare.
|
|
91
|
+
* @param b Second object to compare.
|
|
92
|
+
*
|
|
93
|
+
* @return Comparator result.
|
|
94
|
+
*/
|
|
63
95
|
function compareObjectTabbables(a, b) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
return aTabIndex - bTabIndex;
|
|
96
|
+
const aTabIndex = getTabIndex(a.element);
|
|
97
|
+
const bTabIndex = getTabIndex(b.element);
|
|
98
|
+
if (aTabIndex === bTabIndex) return a.index - b.index;
|
|
99
|
+
return aTabIndex - bTabIndex;
|
|
70
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Given focusable elements, filters out tabbable element.
|
|
103
|
+
*
|
|
104
|
+
* @param focusables Focusable elements to filter.
|
|
105
|
+
*
|
|
106
|
+
* @return Tabbable elements.
|
|
107
|
+
*/
|
|
71
108
|
function filterTabbable(focusables) {
|
|
72
|
-
|
|
109
|
+
return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []);
|
|
73
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* @param context
|
|
113
|
+
* @return Tabbable elements within the context.
|
|
114
|
+
*/
|
|
74
115
|
function find(context) {
|
|
75
|
-
|
|
116
|
+
return filterTabbable((0, __focusable_ts.find)(context));
|
|
76
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Given a focusable element, find the preceding tabbable element.
|
|
120
|
+
*
|
|
121
|
+
* @param element The focusable element before which to look. Defaults
|
|
122
|
+
* to the active element.
|
|
123
|
+
*
|
|
124
|
+
* @return Preceding tabbable element.
|
|
125
|
+
*/
|
|
77
126
|
function findPrevious(element) {
|
|
78
|
-
|
|
79
|
-
(focusable) => (
|
|
80
|
-
// eslint-disable-next-line no-bitwise
|
|
81
|
-
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_PRECEDING
|
|
82
|
-
)
|
|
83
|
-
);
|
|
127
|
+
return filterTabbable((0, __focusable_ts.find)(element.ownerDocument.body)).reverse().find((focusable) => element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_PRECEDING);
|
|
84
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Given a focusable element, find the next tabbable element.
|
|
131
|
+
*
|
|
132
|
+
* @param element The focusable element after which to look. Defaults
|
|
133
|
+
* to the active element.
|
|
134
|
+
*
|
|
135
|
+
* @return Next tabbable element.
|
|
136
|
+
*/
|
|
85
137
|
function findNext(element) {
|
|
86
|
-
|
|
87
|
-
(focusable) => (
|
|
88
|
-
// eslint-disable-next-line no-bitwise
|
|
89
|
-
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_FOLLOWING
|
|
90
|
-
)
|
|
91
|
-
);
|
|
138
|
+
return filterTabbable((0, __focusable_ts.find)(element.ownerDocument.body)).find((focusable) => element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_FOLLOWING);
|
|
92
139
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
//# sourceMappingURL=tabbable.cjs.map
|
|
140
|
+
exports.find = find;
|
|
141
|
+
exports.findNext = findNext;
|
|
142
|
+
exports.findPrevious = findPrevious;
|
|
143
|
+
exports.isTabbableIndex = isTabbableIndex;
|
|
144
|
+
|
|
145
|
+
//# sourceMappingURL=tabbable.cjs.map
|
package/build/tabbable.cjs.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/tabbable.js"],
|
|
4
|
-
"sourcesContent": ["import { find as findFocusable } from './focusable';\n\n/**\n * Returns the tab index of the given element. In contrast with the tabIndex\n * property, this normalizes the default (0) to avoid browser inconsistencies,\n * operating under the assumption that this function is only ever called with a\n * focusable node.\n *\n * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261\n *\n * @param {Element} element Element from which to retrieve.\n *\n * @return {number} Tab index of element (default 0).\n */\nfunction getTabIndex( element ) {\n\tconst tabIndex = element.getAttribute( 'tabindex' );\n\treturn tabIndex === null ? 0 : parseInt( tabIndex, 10 );\n}\n\n/**\n * Returns true if the specified element is tabbable, or false otherwise.\n *\n * @param {Element} element Element to test.\n *\n * @return {boolean} Whether element is tabbable.\n */\nexport function isTabbableIndex( element ) {\n\treturn getTabIndex( element ) !== -1;\n}\n\n/** @typedef {HTMLElement & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */\n\n/**\n * Returns a stateful reducer function which constructs a filtered array of\n * tabbable elements, where at most one radio input is selected for a given\n * name, giving priority to checked input, falling back to the first\n * encountered.\n *\n * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.\n */\nfunction createStatefulCollapseRadioGroup() {\n\t/** @type {Record<string, MaybeHTMLInputElement>} */\n\tconst CHOSEN_RADIO_BY_NAME = {};\n\n\treturn function collapseRadioGroup(\n\t\t/** @type {MaybeHTMLInputElement[]} */ result,\n\t\t/** @type {MaybeHTMLInputElement} */ element\n\t) {\n\t\tconst { nodeName, type, checked, name } = element;\n\n\t\t// For all non-radio tabbables, construct to array by concatenating.\n\t\tif ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {\n\t\t\treturn result.concat( element );\n\t\t}\n\n\t\tconst hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty( name );\n\n\t\t// Omit by skipping concatenation if the radio element is not chosen.\n\t\tconst isChosen = checked || ! hasChosen;\n\t\tif ( ! isChosen ) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// At this point, if there had been a chosen element, the current\n\t\t// element is checked and should take priority. Retroactively remove\n\t\t// the element which had previously been considered the chosen one.\n\t\tif ( hasChosen ) {\n\t\t\tconst hadChosenElement = CHOSEN_RADIO_BY_NAME[ name ];\n\t\t\tresult = result.filter( ( e ) => e !== hadChosenElement );\n\t\t}\n\n\t\tCHOSEN_RADIO_BY_NAME[ name ] = element;\n\n\t\treturn result.concat( element );\n\t};\n}\n\n/**\n * An array map callback, returning an object with the element value and its\n * array index location as properties. This is used to emulate a proper stable\n * sort where equal tabIndex should be left in order of their occurrence in the\n * document.\n *\n * @param {HTMLElement} element Element.\n * @param {number} index Array index of element.\n *\n * @return {{ element: HTMLElement, index: number }} Mapped object with element, index.\n */\nfunction mapElementToObjectTabbable( element, index ) {\n\treturn { element, index };\n}\n\n/**\n * An array map callback, returning an element of the given mapped object's\n * element value.\n *\n * @param {{ element: HTMLElement }} object Mapped object with element.\n *\n * @return {HTMLElement} Mapped object element.\n */\nfunction mapObjectTabbableToElement( object ) {\n\treturn object.element;\n}\n\n/**\n * A sort comparator function used in comparing two objects of mapped elements.\n *\n * @see mapElementToObjectTabbable\n *\n * @param {{ element: HTMLElement, index: number }} a First object to compare.\n * @param {{ element: HTMLElement, index: number }} b Second object to compare.\n *\n * @return {number} Comparator result.\n */\nfunction compareObjectTabbables( a, b ) {\n\tconst aTabIndex = getTabIndex( a.element );\n\tconst bTabIndex = getTabIndex( b.element );\n\n\tif ( aTabIndex === bTabIndex ) {\n\t\treturn a.index - b.index;\n\t}\n\n\treturn aTabIndex - bTabIndex;\n}\n\n/**\n * Given focusable elements, filters out tabbable element.\n *\n * @param {HTMLElement[]} focusables Focusable elements to filter.\n *\n * @return {HTMLElement[]} Tabbable elements.\n */\nfunction filterTabbable( focusables ) {\n\treturn focusables\n\t\t.filter( isTabbableIndex )\n\t\t.map( mapElementToObjectTabbable )\n\t\t.sort( compareObjectTabbables )\n\t\t.map( mapObjectTabbableToElement )\n\t\t.reduce( createStatefulCollapseRadioGroup(), [] );\n}\n\n/**\n * @param {Element} context\n * @return {HTMLElement[]} Tabbable elements within the context.\n */\nexport function find( context ) {\n\treturn filterTabbable( findFocusable( context ) );\n}\n\n/**\n * Given a focusable element, find the preceding tabbable element.\n *\n * @param {Element} element The focusable element before which to look. Defaults\n * to the active element.\n *\n * @return {HTMLElement|undefined} Preceding tabbable element.\n */\nexport function findPrevious( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) )\n\t\t.reverse()\n\t\t.find(\n\t\t\t( focusable ) =>\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\t\telement.DOCUMENT_POSITION_PRECEDING\n\t\t);\n}\n\n/**\n * Given a focusable element, find the next tabbable element.\n *\n * @param {Element} element The focusable element after which to look. Defaults\n * to the active element.\n *\n * @return {HTMLElement|undefined} Next tabbable element.\n */\nexport function findNext( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) ).find(\n\t\t( focusable ) =>\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\telement.DOCUMENT_POSITION_FOLLOWING\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsC;AActC,SAAS,YAAa,SAAU;AAC/B,QAAM,WAAW,QAAQ,aAAc,UAAW;AAClD,SAAO,aAAa,OAAO,IAAI,SAAU,UAAU,EAAG;AACvD;AASO,SAAS,gBAAiB,SAAU;AAC1C,SAAO,YAAa,OAAQ,MAAM;AACnC;AAYA,SAAS,mCAAmC;AAE3C,QAAM,uBAAuB,CAAC;AAE9B,SAAO,SAAS,mBACwB,QACF,SACpC;AACD,UAAM,EAAE,UAAU,MAAM,SAAS,KAAK,IAAI;AAG1C,QAAK,aAAa,WAAW,SAAS,WAAW,CAAE,MAAO;AACzD,aAAO,OAAO,OAAQ,OAAQ;AAAA,IAC/B;AAEA,UAAM,YAAY,qBAAqB,eAAgB,IAAK;AAG5D,UAAM,WAAW,WAAW,CAAE;AAC9B,QAAK,CAAE,UAAW;AACjB,aAAO;AAAA,IACR;AAKA,QAAK,WAAY;AAChB,YAAM,mBAAmB,qBAAsB,IAAK;AACpD,eAAS,OAAO,OAAQ,CAAE,MAAO,MAAM,gBAAiB;AAAA,IACzD;AAEA,yBAAsB,IAAK,IAAI;AAE/B,WAAO,OAAO,OAAQ,OAAQ;AAAA,EAC/B;AACD;AAaA,SAAS,2BAA4B,SAAS,OAAQ;AACrD,SAAO,EAAE,SAAS,MAAM;AACzB;AAUA,SAAS,2BAA4B,QAAS;AAC7C,SAAO,OAAO;AACf;AAYA,SAAS,uBAAwB,GAAG,GAAI;AACvC,QAAM,YAAY,YAAa,EAAE,OAAQ;AACzC,QAAM,YAAY,YAAa,EAAE,OAAQ;AAEzC,MAAK,cAAc,WAAY;AAC9B,WAAO,EAAE,QAAQ,EAAE;AAAA,EACpB;AAEA,SAAO,YAAY;AACpB;AASA,SAAS,eAAgB,YAAa;AACrC,SAAO,WACL,OAAQ,eAAgB,EACxB,IAAK,0BAA2B,EAChC,KAAM,sBAAuB,EAC7B,IAAK,0BAA2B,EAChC,OAAQ,iCAAiC,GAAG,CAAC,CAAE;AAClD;AAMO,SAAS,KAAM,SAAU;AAC/B,SAAO,mBAAgB,iBAAAA,MAAe,OAAQ,CAAE;AACjD;AAUO,SAAS,aAAc,SAAU;AACvC,SAAO,mBAAgB,iBAAAA,MAAe,QAAQ,cAAc,IAAK,CAAE,EACjE,QAAQ,EACR;AAAA,IACA,CAAE;AAAA;AAAA,MAED,QAAQ,wBAAyB,SAAU,IAC3C,QAAQ;AAAA;AAAA,EACV;AACF;AAUO,SAAS,SAAU,SAAU;AACnC,SAAO,mBAAgB,iBAAAA,MAAe,QAAQ,cAAc,IAAK,CAAE,EAAE;AAAA,IACpE,CAAE;AAAA;AAAA,MAED,QAAQ,wBAAyB,SAAU,IAC3C,QAAQ;AAAA;AAAA,EACV;AACD;",
|
|
6
|
-
"names": ["findFocusable"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"tabbable.cjs","names":["findFocusable"],"sources":["../src/tabbable.ts"],"sourcesContent":["import type { MaybeHTMLInputElement, ObjectTabbable } from './types';\nimport { find as findFocusable } from './focusable';\n\n/**\n * Returns the tab index of the given element. In contrast with the tabIndex\n * property, this normalizes the default (0) to avoid browser inconsistencies,\n * operating under the assumption that this function is only ever called with a\n * focusable node.\n *\n * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261\n *\n * @param element Element from which to retrieve.\n *\n * @return Tab index of element (default 0).\n */\nfunction getTabIndex( element: Element ): number {\n\tconst tabIndex = element.getAttribute( 'tabindex' );\n\treturn tabIndex === null ? 0 : parseInt( tabIndex, 10 );\n}\n\n/**\n * Returns true if the specified element is tabbable, or false otherwise.\n *\n * @param element Element to test.\n *\n * @return Whether element is tabbable.\n */\nexport function isTabbableIndex( element: Element ): boolean {\n\treturn getTabIndex( element ) !== -1;\n}\n\n/**\n * Returns a stateful reducer function which constructs a filtered array of\n * tabbable elements, where at most one radio input is selected for a given\n * name, giving priority to checked input, falling back to the first\n * encountered.\n *\n * @return Radio group collapse reducer.\n */\nfunction createStatefulCollapseRadioGroup(): (\n\tacc: MaybeHTMLInputElement[],\n\tel: MaybeHTMLInputElement\n) => MaybeHTMLInputElement[] {\n\tconst CHOSEN_RADIO_BY_NAME: Record< string, MaybeHTMLInputElement > = {};\n\n\treturn function collapseRadioGroup(\n\t\tresult: MaybeHTMLInputElement[],\n\t\telement: MaybeHTMLInputElement\n\t) {\n\t\tconst { nodeName, type, checked, name } = element;\n\n\t\t// For all non-radio tabbables, construct to array by concatenating.\n\t\tif ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {\n\t\t\treturn result.concat( element );\n\t\t}\n\n\t\tconst hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty( name );\n\n\t\t// Omit by skipping concatenation if the radio element is not chosen.\n\t\tconst isChosen = checked || ! hasChosen;\n\t\tif ( ! isChosen ) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// At this point, if there had been a chosen element, the current\n\t\t// element is checked and should take priority. Retroactively remove\n\t\t// the element which had previously been considered the chosen one.\n\t\tif ( hasChosen ) {\n\t\t\tconst hadChosenElement = CHOSEN_RADIO_BY_NAME[ name ];\n\t\t\tresult = result.filter( ( e ) => e !== hadChosenElement );\n\t\t}\n\n\t\tCHOSEN_RADIO_BY_NAME[ name ] = element;\n\n\t\treturn result.concat( element );\n\t};\n}\n\n/**\n * An array map callback, returning an object with the element value and its\n * array index location as properties. This is used to emulate a proper stable\n * sort where equal tabIndex should be left in order of their occurrence in the\n * document.\n *\n * @param element Element.\n * @param index Array index of element.\n *\n * @return Mapped object with element, index.\n */\nfunction mapElementToObjectTabbable(\n\telement: HTMLElement,\n\tindex: number\n): ObjectTabbable {\n\treturn { element, index };\n}\n\n/**\n * An array map callback, returning an element of the given mapped object's\n * element value.\n *\n * @param object Mapped object with element.\n *\n * @return Mapped object element.\n */\nfunction mapObjectTabbableToElement(\n\tobject: Pick< ObjectTabbable, 'element' >\n): HTMLElement {\n\treturn object.element;\n}\n\n/**\n * A sort comparator function used in comparing two objects of mapped elements.\n *\n * @see mapElementToObjectTabbable\n *\n * @param a First object to compare.\n * @param b Second object to compare.\n *\n * @return Comparator result.\n */\nfunction compareObjectTabbables(\n\ta: ObjectTabbable,\n\tb: ObjectTabbable\n): number {\n\tconst aTabIndex = getTabIndex( a.element );\n\tconst bTabIndex = getTabIndex( b.element );\n\n\tif ( aTabIndex === bTabIndex ) {\n\t\treturn a.index - b.index;\n\t}\n\n\treturn aTabIndex - bTabIndex;\n}\n\n/**\n * Given focusable elements, filters out tabbable element.\n *\n * @param focusables Focusable elements to filter.\n *\n * @return Tabbable elements.\n */\nfunction filterTabbable( focusables: HTMLElement[] ): HTMLElement[] {\n\treturn focusables\n\t\t.filter( isTabbableIndex )\n\t\t.map( mapElementToObjectTabbable )\n\t\t.sort( compareObjectTabbables )\n\t\t.map( mapObjectTabbableToElement )\n\t\t.reduce( createStatefulCollapseRadioGroup(), [] );\n}\n\n/**\n * @param context\n * @return Tabbable elements within the context.\n */\nexport function find( context: Element ): HTMLElement[] {\n\treturn filterTabbable( findFocusable( context ) );\n}\n\n/**\n * Given a focusable element, find the preceding tabbable element.\n *\n * @param element The focusable element before which to look. Defaults\n * to the active element.\n *\n * @return Preceding tabbable element.\n */\nexport function findPrevious( element: Element ): HTMLElement | undefined {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) )\n\t\t.reverse()\n\t\t.find(\n\t\t\t( focusable ) =>\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\t\telement.DOCUMENT_POSITION_PRECEDING\n\t\t);\n}\n\n/**\n * Given a focusable element, find the next tabbable element.\n *\n * @param element The focusable element after which to look. Defaults\n * to the active element.\n *\n * @return Next tabbable element.\n */\nexport function findNext( element: Element ): HTMLElement | undefined {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) ).find(\n\t\t( focusable ) =>\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\telement.DOCUMENT_POSITION_FOLLOWING\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAeA,SAAS,YAAa,SAA2B;CAChD,MAAM,WAAW,QAAQ,aAAc,UAAW;CAClD,OAAO,aAAa,OAAO,IAAI,SAAU,UAAU,EAAG;AACvD;;;;;;;;AASA,SAAgB,gBAAiB,SAA4B;CAC5D,OAAO,YAAa,OAAQ,MAAM;AACnC;;;;;;;;;AAUA,SAAS,mCAGoB;CAC5B,MAAM,uBAAgE,CAAC;CAEvE,OAAO,SAAS,mBACf,QACA,SACC;EACD,MAAM,EAAE,UAAU,MAAM,SAAS,SAAS;EAG1C,IAAK,aAAa,WAAW,SAAS,WAAW,CAAE,MAClD,OAAO,OAAO,OAAQ,OAAQ;EAG/B,MAAM,YAAY,qBAAqB,eAAgB,IAAK;EAI5D,IAAK,EADY,WAAW,CAAE,YAE7B,OAAO;EAMR,IAAK,WAAY;GAChB,MAAM,mBAAmB,qBAAsB;GAC/C,SAAS,OAAO,QAAU,MAAO,MAAM,gBAAiB;EACzD;EAEA,qBAAsB,QAAS;EAE/B,OAAO,OAAO,OAAQ,OAAQ;CAC/B;AACD;;;;;;;;;;;;AAaA,SAAS,2BACR,SACA,OACiB;CACjB,OAAO;EAAE;EAAS;CAAM;AACzB;;;;;;;;;AAUA,SAAS,2BACR,QACc;CACd,OAAO,OAAO;AACf;;;;;;;;;;;AAYA,SAAS,uBACR,GACA,GACS;CACT,MAAM,YAAY,YAAa,EAAE,OAAQ;CACzC,MAAM,YAAY,YAAa,EAAE,OAAQ;CAEzC,IAAK,cAAc,WAClB,OAAO,EAAE,QAAQ,EAAE;CAGpB,OAAO,YAAY;AACpB;;;;;;;;AASA,SAAS,eAAgB,YAA2C;CACnE,OAAO,WACL,OAAQ,eAAgB,CAAC,CACzB,IAAK,0BAA2B,CAAC,CACjC,KAAM,sBAAuB,CAAC,CAC9B,IAAK,0BAA2B,CAAC,CACjC,OAAQ,iCAAiC,GAAG,CAAC,CAAE;AAClD;;;;;AAMA,SAAgB,KAAM,SAAkC;CACvD,OAAO,gBAAA,GAAgBA,eAAAA,KAAAA,CAAe,OAAQ,CAAE;AACjD;;;;;;;;;AAUA,SAAgB,aAAc,SAA4C;CACzE,OAAO,gBAAA,GAAgBA,eAAAA,KAAAA,CAAe,QAAQ,cAAc,IAAK,CAAE,CAAC,CAClE,QAAQ,CAAC,CACT,MACE,cAED,QAAQ,wBAAyB,SAAU,IAC3C,QAAQ,2BACV;AACF;;;;;;;;;AAUA,SAAgB,SAAU,SAA4C;CACrE,OAAO,gBAAA,GAAgBA,eAAAA,KAAAA,CAAe,QAAQ,cAAc,IAAK,CAAE,CAAC,CAAC,MAClE,cAED,QAAQ,wBAAyB,SAAU,IAC3C,QAAQ,2BACV;AACD"}
|