@selenium/atoms 4.51.0 → 4.53.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 +56 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -1
- package/dist/typescript/accessibility-snapshot-wire.d.ts +4 -0
- package/dist/typescript/accessibility-snapshot-wire.d.ts.map +1 -0
- package/dist/typescript/accessibility-snapshot-wire.js +18 -0
- package/dist/typescript/accessibility-snapshot-wire.js.map +1 -0
- package/dist/typescript/accessibility-snapshot.d.ts +3 -0
- package/dist/typescript/accessibility-snapshot.d.ts.map +1 -0
- package/dist/typescript/accessibility-snapshot.js +18 -0
- package/dist/typescript/accessibility-snapshot.js.map +1 -0
- package/dist/typescript/active-element.d.ts +2 -0
- package/dist/typescript/active-element.d.ts.map +1 -0
- package/dist/typescript/active-element.js +19 -0
- package/dist/typescript/active-element.js.map +1 -0
- package/dist/typescript/clear-local-storage.d.ts +3 -0
- package/dist/typescript/clear-local-storage.d.ts.map +1 -0
- package/dist/typescript/clear-local-storage.js +25 -0
- package/dist/typescript/clear-local-storage.js.map +1 -0
- package/dist/typescript/clear-session-storage.d.ts +3 -0
- package/dist/typescript/clear-session-storage.d.ts.map +1 -0
- package/dist/typescript/clear-session-storage.js +25 -0
- package/dist/typescript/clear-session-storage.js.map +1 -0
- package/dist/typescript/clear.d.ts +3 -0
- package/dist/typescript/clear.d.ts.map +1 -0
- package/dist/typescript/clear.js +67 -0
- package/dist/typescript/clear.js.map +1 -0
- package/dist/typescript/click.d.ts +4 -0
- package/dist/typescript/click.d.ts.map +1 -0
- package/dist/typescript/click.js +52 -0
- package/dist/typescript/click.js.map +1 -0
- package/dist/typescript/core/accessibility/accname.d.ts +6 -0
- package/dist/typescript/core/accessibility/accname.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/accname.js +537 -0
- package/dist/typescript/core/accessibility/accname.js.map +1 -0
- package/dist/typescript/core/accessibility/context.d.ts +43 -0
- package/dist/typescript/core/accessibility/context.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/context.js +49 -0
- package/dist/typescript/core/accessibility/context.js.map +1 -0
- package/dist/typescript/core/accessibility/hidden.d.ts +39 -0
- package/dist/typescript/core/accessibility/hidden.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/hidden.js +216 -0
- package/dist/typescript/core/accessibility/hidden.js.map +1 -0
- package/dist/typescript/core/accessibility/roles.d.ts +28 -0
- package/dist/typescript/core/accessibility/roles.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/roles.js +381 -0
- package/dist/typescript/core/accessibility/roles.js.map +1 -0
- package/dist/typescript/core/accessibility/snapshot.d.ts +13 -0
- package/dist/typescript/core/accessibility/snapshot.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/snapshot.js +55 -0
- package/dist/typescript/core/accessibility/snapshot.js.map +1 -0
- package/dist/typescript/core/accessibility/states.d.ts +18 -0
- package/dist/typescript/core/accessibility/states.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/states.js +215 -0
- package/dist/typescript/core/accessibility/states.js.map +1 -0
- package/dist/typescript/core/accessibility/tree.d.ts +10 -0
- package/dist/typescript/core/accessibility/tree.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/tree.js +261 -0
- package/dist/typescript/core/accessibility/tree.js.map +1 -0
- package/dist/typescript/core/accessibility/types.d.ts +30 -0
- package/dist/typescript/core/accessibility/types.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/types.js +18 -0
- package/dist/typescript/core/accessibility/types.js.map +1 -0
- package/dist/typescript/core/accessibility/value.d.ts +4 -0
- package/dist/typescript/core/accessibility/value.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/value.js +83 -0
- package/dist/typescript/core/accessibility/value.js.map +1 -0
- package/dist/typescript/core/accessibility/wire.d.ts +57 -0
- package/dist/typescript/core/accessibility/wire.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/wire.js +72 -0
- package/dist/typescript/core/accessibility/wire.js.map +1 -0
- package/dist/typescript/core/attribute.d.ts +3 -0
- package/dist/typescript/core/attribute.d.ts.map +1 -0
- package/dist/typescript/core/attribute.js +60 -0
- package/dist/typescript/core/attribute.js.map +1 -0
- package/dist/typescript/core/color.d.ts +2 -0
- package/dist/typescript/core/color.d.ts.map +1 -0
- package/dist/typescript/core/color.js +248 -0
- package/dist/typescript/core/color.js.map +1 -0
- package/dist/typescript/core/editable.d.ts +5 -0
- package/dist/typescript/core/editable.d.ts.map +1 -0
- package/dist/typescript/core/editable.js +55 -0
- package/dist/typescript/core/editable.js.map +1 -0
- package/dist/typescript/core/element.d.ts +6 -0
- package/dist/typescript/core/element.d.ts.map +1 -0
- package/dist/typescript/core/element.js +97 -0
- package/dist/typescript/core/element.js.map +1 -0
- package/dist/typescript/core/enabled.d.ts +2 -0
- package/dist/typescript/core/enabled.d.ts.map +1 -0
- package/dist/typescript/core/enabled.js +69 -0
- package/dist/typescript/core/enabled.js.map +1 -0
- package/dist/typescript/core/error.d.ts +13 -0
- package/dist/typescript/core/error.d.ts.map +1 -0
- package/dist/typescript/core/error.js +40 -0
- package/dist/typescript/core/error.js.map +1 -0
- package/dist/typescript/core/events.d.ts +91 -0
- package/dist/typescript/core/events.d.ts.map +1 -0
- package/dist/typescript/core/events.js +131 -0
- package/dist/typescript/core/events.js.map +1 -0
- package/dist/typescript/core/focus.d.ts +4 -0
- package/dist/typescript/core/focus.d.ts.map +1 -0
- package/dist/typescript/core/focus.js +88 -0
- package/dist/typescript/core/focus.js.map +1 -0
- package/dist/typescript/core/focusable.d.ts +2 -0
- package/dist/typescript/core/focusable.d.ts.map +1 -0
- package/dist/typescript/core/focusable.js +36 -0
- package/dist/typescript/core/focusable.js.map +1 -0
- package/dist/typescript/core/form.d.ts +2 -0
- package/dist/typescript/core/form.d.ts.map +1 -0
- package/dist/typescript/core/form.js +76 -0
- package/dist/typescript/core/form.js.map +1 -0
- package/dist/typescript/core/frame.d.ts +8 -0
- package/dist/typescript/core/frame.d.ts.map +1 -0
- package/dist/typescript/core/frame.js +95 -0
- package/dist/typescript/core/frame.js.map +1 -0
- package/dist/typescript/core/geometry.d.ts +28 -0
- package/dist/typescript/core/geometry.d.ts.map +1 -0
- package/dist/typescript/core/geometry.js +134 -0
- package/dist/typescript/core/geometry.js.map +1 -0
- package/dist/typescript/core/inject.d.ts +21 -0
- package/dist/typescript/core/inject.d.ts.map +1 -0
- package/dist/typescript/core/inject.js +282 -0
- package/dist/typescript/core/inject.js.map +1 -0
- package/dist/typescript/core/interactable.d.ts +2 -0
- package/dist/typescript/core/interactable.d.ts.map +1 -0
- package/dist/typescript/core/interactable.js +27 -0
- package/dist/typescript/core/interactable.js.map +1 -0
- package/dist/typescript/core/keyboard.d.ts +15 -0
- package/dist/typescript/core/keyboard.d.ts.map +1 -0
- package/dist/typescript/core/keyboard.js +356 -0
- package/dist/typescript/core/keyboard.js.map +1 -0
- package/dist/typescript/core/keys.d.ts +65 -0
- package/dist/typescript/core/keys.d.ts.map +1 -0
- package/dist/typescript/core/keys.js +125 -0
- package/dist/typescript/core/keys.js.map +1 -0
- package/dist/typescript/core/locators.d.ts +6 -0
- package/dist/typescript/core/locators.d.ts.map +1 -0
- package/dist/typescript/core/locators.js +610 -0
- package/dist/typescript/core/locators.js.map +1 -0
- package/dist/typescript/core/mouse.d.ts +17 -0
- package/dist/typescript/core/mouse.d.ts.map +1 -0
- package/dist/typescript/core/mouse.js +186 -0
- package/dist/typescript/core/mouse.js.map +1 -0
- package/dist/typescript/core/overflow.d.ts +5 -0
- package/dist/typescript/core/overflow.d.ts.map +1 -0
- package/dist/typescript/core/overflow.js +133 -0
- package/dist/typescript/core/overflow.js.map +1 -0
- package/dist/typescript/core/scroll.d.ts +3 -0
- package/dist/typescript/core/scroll.d.ts.map +1 -0
- package/dist/typescript/core/scroll.js +77 -0
- package/dist/typescript/core/scroll.js.map +1 -0
- package/dist/typescript/core/shown.d.ts +3 -0
- package/dist/typescript/core/shown.d.ts.map +1 -0
- package/dist/typescript/core/shown.js +190 -0
- package/dist/typescript/core/shown.js.map +1 -0
- package/dist/typescript/core/storage.d.ts +14 -0
- package/dist/typescript/core/storage.d.ts.map +1 -0
- package/dist/typescript/core/storage.js +98 -0
- package/dist/typescript/core/storage.js.map +1 -0
- package/dist/typescript/core/style.d.ts +2 -0
- package/dist/typescript/core/style.d.ts.map +1 -0
- package/dist/typescript/core/style.js +32 -0
- package/dist/typescript/core/style.js.map +1 -0
- package/dist/typescript/core/useragent.d.ts +3 -0
- package/dist/typescript/core/useragent.d.ts.map +1 -0
- package/dist/typescript/core/useragent.js +31 -0
- package/dist/typescript/core/useragent.js.map +1 -0
- package/dist/typescript/default-content.d.ts +2 -0
- package/dist/typescript/default-content.d.ts.map +1 -0
- package/dist/typescript/default-content.js +20 -0
- package/dist/typescript/default-content.js.map +1 -0
- package/dist/typescript/execute-async-script.d.ts +2 -0
- package/dist/typescript/execute-async-script.d.ts.map +1 -0
- package/dist/typescript/execute-async-script.js +20 -0
- package/dist/typescript/execute-async-script.js.map +1 -0
- package/dist/typescript/execute-script.d.ts +2 -0
- package/dist/typescript/execute-script.d.ts.map +1 -0
- package/dist/typescript/execute-script.js +20 -0
- package/dist/typescript/execute-script.js.map +1 -0
- package/dist/typescript/find-element-fragment.d.ts +8 -0
- package/dist/typescript/find-element-fragment.d.ts.map +1 -0
- package/dist/typescript/find-element-fragment.js +39 -0
- package/dist/typescript/find-element-fragment.js.map +1 -0
- package/dist/typescript/find-element.d.ts +2 -0
- package/dist/typescript/find-element.d.ts.map +1 -0
- package/dist/typescript/find-element.js +18 -0
- package/dist/typescript/find-element.js.map +1 -0
- package/dist/typescript/find-elements.d.ts +1 -2
- package/dist/typescript/find-elements.d.ts.map +1 -1
- package/dist/typescript/find-elements.js +1 -289
- package/dist/typescript/find-elements.js.map +1 -1
- package/dist/typescript/frame-by-id-or-name.d.ts +2 -0
- package/dist/typescript/frame-by-id-or-name.d.ts.map +1 -0
- package/dist/typescript/frame-by-id-or-name.js +22 -0
- package/dist/typescript/frame-by-id-or-name.js.map +1 -0
- package/dist/typescript/frame-by-index.d.ts +2 -0
- package/dist/typescript/frame-by-index.d.ts.map +1 -0
- package/dist/typescript/frame-by-index.js +19 -0
- package/dist/typescript/frame-by-index.js.map +1 -0
- package/dist/typescript/get-attribute-value.d.ts +2 -0
- package/dist/typescript/get-attribute-value.d.ts.map +1 -0
- package/dist/typescript/get-attribute-value.js +22 -0
- package/dist/typescript/get-attribute-value.js.map +1 -0
- package/dist/typescript/get-effective-style.d.ts +3 -0
- package/dist/typescript/get-effective-style.d.ts.map +1 -0
- package/dist/typescript/get-effective-style.js +84 -0
- package/dist/typescript/get-effective-style.js.map +1 -0
- package/dist/typescript/get-element-from-cache.d.ts +2 -0
- package/dist/typescript/get-element-from-cache.d.ts.map +1 -0
- package/dist/typescript/get-element-from-cache.js +20 -0
- package/dist/typescript/get-element-from-cache.js.map +1 -0
- package/dist/typescript/get-frame-window.d.ts +2 -0
- package/dist/typescript/get-frame-window.d.ts.map +1 -0
- package/dist/typescript/get-frame-window.js +22 -0
- package/dist/typescript/get-frame-window.js.map +1 -0
- package/dist/typescript/get-local-storage-item.d.ts +3 -0
- package/dist/typescript/get-local-storage-item.d.ts.map +1 -0
- package/dist/typescript/get-local-storage-item.js +25 -0
- package/dist/typescript/get-local-storage-item.js.map +1 -0
- package/dist/typescript/get-local-storage-key.d.ts +3 -0
- package/dist/typescript/get-local-storage-key.d.ts.map +1 -0
- package/dist/typescript/get-local-storage-key.js +26 -0
- package/dist/typescript/get-local-storage-key.js.map +1 -0
- package/dist/typescript/get-local-storage-keys.d.ts +3 -0
- package/dist/typescript/get-local-storage-keys.d.ts.map +1 -0
- package/dist/typescript/get-local-storage-keys.js +25 -0
- package/dist/typescript/get-local-storage-keys.js.map +1 -0
- package/dist/typescript/get-local-storage-size.d.ts +3 -0
- package/dist/typescript/get-local-storage-size.d.ts.map +1 -0
- package/dist/typescript/get-local-storage-size.js +25 -0
- package/dist/typescript/get-local-storage-size.js.map +1 -0
- package/dist/typescript/get-location.d.ts +9 -0
- package/dist/typescript/get-location.d.ts.map +1 -0
- package/dist/typescript/get-location.js +49 -0
- package/dist/typescript/get-location.js.map +1 -0
- package/dist/typescript/get-session-storage-item.d.ts +3 -0
- package/dist/typescript/get-session-storage-item.d.ts.map +1 -0
- package/dist/typescript/get-session-storage-item.js +25 -0
- package/dist/typescript/get-session-storage-item.js.map +1 -0
- package/dist/typescript/get-session-storage-key.d.ts +3 -0
- package/dist/typescript/get-session-storage-key.d.ts.map +1 -0
- package/dist/typescript/get-session-storage-key.js +26 -0
- package/dist/typescript/get-session-storage-key.js.map +1 -0
- package/dist/typescript/get-session-storage-keys.d.ts +3 -0
- package/dist/typescript/get-session-storage-keys.d.ts.map +1 -0
- package/dist/typescript/get-session-storage-keys.js +25 -0
- package/dist/typescript/get-session-storage-keys.js.map +1 -0
- package/dist/typescript/get-session-storage-size.d.ts +3 -0
- package/dist/typescript/get-session-storage-size.d.ts.map +1 -0
- package/dist/typescript/get-session-storage-size.js +25 -0
- package/dist/typescript/get-session-storage-size.js.map +1 -0
- package/dist/typescript/get-size.d.ts +7 -0
- package/dist/typescript/get-size.d.ts.map +1 -0
- package/dist/typescript/get-size.js +36 -0
- package/dist/typescript/get-size.js.map +1 -0
- package/dist/typescript/get-text.d.ts +3 -0
- package/dist/typescript/get-text.d.ts.map +1 -0
- package/dist/typescript/get-text.js +294 -0
- package/dist/typescript/get-text.js.map +1 -0
- package/dist/typescript/get-top-left-coordinates.d.ts +4 -0
- package/dist/typescript/get-top-left-coordinates.d.ts.map +1 -0
- package/dist/typescript/get-top-left-coordinates.js +36 -0
- package/dist/typescript/get-top-left-coordinates.js.map +1 -0
- package/dist/typescript/is-displayed.d.ts +1 -2
- package/dist/typescript/is-displayed.d.ts.map +1 -1
- package/dist/typescript/is-displayed.js +3 -396
- package/dist/typescript/is-displayed.js.map +1 -1
- package/dist/typescript/is-editable.d.ts +2 -0
- package/dist/typescript/is-editable.d.ts.map +1 -0
- package/dist/typescript/is-editable.js +18 -0
- package/dist/typescript/is-editable.js.map +1 -0
- package/dist/typescript/is-enabled.d.ts +2 -0
- package/dist/typescript/is-enabled.d.ts.map +1 -0
- package/dist/typescript/is-enabled.js +18 -0
- package/dist/typescript/is-enabled.js.map +1 -0
- package/dist/typescript/is-focusable.d.ts +2 -0
- package/dist/typescript/is-focusable.d.ts.map +1 -0
- package/dist/typescript/is-focusable.js +20 -0
- package/dist/typescript/is-focusable.js.map +1 -0
- package/dist/typescript/is-interactable.d.ts +2 -0
- package/dist/typescript/is-interactable.d.ts.map +1 -0
- package/dist/typescript/is-interactable.js +19 -0
- package/dist/typescript/is-interactable.js.map +1 -0
- package/dist/typescript/is-selected.d.ts +3 -0
- package/dist/typescript/is-selected.d.ts.map +1 -0
- package/dist/typescript/is-selected.js +29 -0
- package/dist/typescript/is-selected.js.map +1 -0
- package/dist/typescript/remove-local-storage-item.d.ts +3 -0
- package/dist/typescript/remove-local-storage-item.d.ts.map +1 -0
- package/dist/typescript/remove-local-storage-item.js +25 -0
- package/dist/typescript/remove-local-storage-item.js.map +1 -0
- package/dist/typescript/remove-session-storage-item.d.ts +3 -0
- package/dist/typescript/remove-session-storage-item.d.ts.map +1 -0
- package/dist/typescript/remove-session-storage-item.js +25 -0
- package/dist/typescript/remove-session-storage-item.js.map +1 -0
- package/dist/typescript/set-local-storage-item.d.ts +3 -0
- package/dist/typescript/set-local-storage-item.d.ts.map +1 -0
- package/dist/typescript/set-local-storage-item.js +26 -0
- package/dist/typescript/set-local-storage-item.js.map +1 -0
- package/dist/typescript/set-session-storage-item.d.ts +3 -0
- package/dist/typescript/set-session-storage-item.d.ts.map +1 -0
- package/dist/typescript/set-session-storage-item.js +26 -0
- package/dist/typescript/set-session-storage-item.js.map +1 -0
- package/dist/typescript/submit.d.ts +3 -0
- package/dist/typescript/submit.d.ts.map +1 -0
- package/dist/typescript/submit.js +50 -0
- package/dist/typescript/submit.js.map +1 -0
- package/dist/typescript/type.d.ts +3 -0
- package/dist/typescript/type.d.ts.map +1 -0
- package/dist/typescript/type.js +201 -0
- package/dist/typescript/type.js.map +1 -0
- package/index.ts +44 -0
- package/package.json +306 -5
- package/typescript/accessibility-snapshot-wire.ts +20 -0
- package/typescript/accessibility-snapshot.ts +21 -0
- package/typescript/active-element.ts +19 -0
- package/typescript/clear-local-storage.ts +27 -0
- package/typescript/clear-session-storage.ts +27 -0
- package/typescript/clear.ts +73 -0
- package/typescript/click.ts +55 -0
- package/typescript/core/accessibility/accname.ts +587 -0
- package/typescript/core/accessibility/context.ts +116 -0
- package/typescript/core/accessibility/hidden.ts +242 -0
- package/typescript/core/accessibility/roles.ts +410 -0
- package/typescript/core/accessibility/snapshot.ts +61 -0
- package/typescript/core/accessibility/states.ts +233 -0
- package/typescript/core/accessibility/tree.ts +306 -0
- package/typescript/core/accessibility/types.ts +52 -0
- package/typescript/core/accessibility/value.ts +89 -0
- package/typescript/core/accessibility/wire.ts +123 -0
- package/typescript/core/attribute.ts +68 -0
- package/typescript/core/color.ts +257 -0
- package/typescript/core/editable.ts +63 -0
- package/typescript/core/element.ts +110 -0
- package/typescript/core/enabled.ts +76 -0
- package/typescript/core/error.ts +41 -0
- package/typescript/core/events.ts +268 -0
- package/typescript/core/focus.ts +92 -0
- package/typescript/core/focusable.ts +38 -0
- package/typescript/core/form.ts +81 -0
- package/typescript/core/frame.ts +105 -0
- package/typescript/core/geometry.ts +183 -0
- package/typescript/core/inject.ts +336 -0
- package/typescript/core/interactable.ts +30 -0
- package/typescript/core/keyboard.ts +369 -0
- package/typescript/core/keys.ts +204 -0
- package/typescript/core/locators.ts +704 -0
- package/typescript/core/mouse.ts +211 -0
- package/typescript/core/overflow.ts +172 -0
- package/typescript/core/scroll.ts +92 -0
- package/typescript/core/shown.ts +233 -0
- package/typescript/core/storage.ts +111 -0
- package/typescript/core/style.ts +32 -0
- package/typescript/core/useragent.ts +33 -0
- package/typescript/default-content.ts +20 -0
- package/typescript/execute-async-script.ts +20 -0
- package/typescript/execute-script.ts +20 -0
- package/typescript/find-element-fragment.ts +45 -0
- package/typescript/find-element.ts +18 -0
- package/typescript/find-elements.ts +1 -326
- package/typescript/frame-by-id-or-name.ts +22 -0
- package/typescript/frame-by-index.ts +19 -0
- package/typescript/get-attribute-value.ts +22 -0
- package/typescript/get-effective-style.ts +93 -0
- package/typescript/get-element-from-cache.ts +20 -0
- package/typescript/get-frame-window.ts +22 -0
- package/typescript/get-local-storage-item.ts +27 -0
- package/typescript/get-local-storage-key.ts +28 -0
- package/typescript/get-local-storage-keys.ts +27 -0
- package/typescript/get-local-storage-size.ts +27 -0
- package/typescript/get-location.ts +63 -0
- package/typescript/get-session-storage-item.ts +27 -0
- package/typescript/get-session-storage-key.ts +28 -0
- package/typescript/get-session-storage-keys.ts +27 -0
- package/typescript/get-session-storage-size.ts +27 -0
- package/typescript/get-size.ts +43 -0
- package/typescript/get-text.ts +353 -0
- package/typescript/get-top-left-coordinates.ts +38 -0
- package/typescript/is-displayed.ts +3 -498
- package/typescript/is-editable.ts +18 -0
- package/typescript/is-enabled.ts +18 -0
- package/typescript/is-focusable.ts +20 -0
- package/typescript/is-interactable.ts +19 -0
- package/typescript/is-selected.ts +31 -0
- package/typescript/remove-local-storage-item.ts +27 -0
- package/typescript/remove-session-storage-item.ts +27 -0
- package/typescript/set-local-storage-item.ts +28 -0
- package/typescript/set-session-storage-item.ts +28 -0
- package/typescript/submit.ts +53 -0
- package/typescript/type.ts +210 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
+
// or more contributor license agreements. See the NOTICE file
|
|
3
|
+
// distributed with this work for additional information
|
|
4
|
+
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
+
// to you under the Apache License, Version 2.0 (the
|
|
6
|
+
// "License"); you may not use this file except in compliance
|
|
7
|
+
// with the License. You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing,
|
|
12
|
+
// software distributed under the License is distributed on an
|
|
13
|
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
// KIND, either express or implied. See the License for the
|
|
15
|
+
// specific language governing permissions and limitations
|
|
16
|
+
// under the License.
|
|
17
|
+
|
|
18
|
+
import { UNKNOWN_ERROR, botError } from './error.js'
|
|
19
|
+
import { type EventFactory, EventType, type PointerArgs, fire } from './events.js'
|
|
20
|
+
import { focusOnElement, getActiveElementFrom } from './focus.js'
|
|
21
|
+
import { getClientRect } from './geometry.js'
|
|
22
|
+
import { isInteractable } from './interactable.js'
|
|
23
|
+
|
|
24
|
+
// A virtual mouse that produces what a real one does with its primary button,
|
|
25
|
+
// in the order Chrome produces for a real click (recorded 2026-10-13):
|
|
26
|
+
//
|
|
27
|
+
// move: pointerout, pointerleave*, pointerover, pointerenter*,
|
|
28
|
+
// mouseout, mouseleave*, mouseover, mouseenter*,
|
|
29
|
+
// pointermove, mousemove
|
|
30
|
+
// press: pointerdown, mousedown, then focus
|
|
31
|
+
// release: pointerup, mouseup, click
|
|
32
|
+
//
|
|
33
|
+
// The click itself runs the target's activation behaviour natively -- links
|
|
34
|
+
// navigate, checkboxes toggle with input and change, labels forward to their
|
|
35
|
+
// control, submit buttons submit -- so none of that is simulated here.
|
|
36
|
+
//
|
|
37
|
+
// Replaces bot.Mouse for the click atom. Differences, all toward real input:
|
|
38
|
+
// - Pointer events and mouseenter/mouseleave are fired; bot.Mouse fired
|
|
39
|
+
// neither. Enter and leave go to every ancestor up to the common one.
|
|
40
|
+
// - A cancelled pointerdown suppresses mousedown and mouseup (and so the
|
|
41
|
+
// focus change) but not the click, as Pointer Events specifies.
|
|
42
|
+
// - Releasing over a different element clicks the nearest common ancestor,
|
|
43
|
+
// as UI Events specifies; bot.Mouse clicked nothing.
|
|
44
|
+
// - Focus and the mousedown-handler-moved-focus check apply in every engine;
|
|
45
|
+
// bot.Mouse only checked in Firefox.
|
|
46
|
+
// - Links are not followed by hand. Firefox already follows a dispatched
|
|
47
|
+
// click, so bot.Mouse navigated there twice.
|
|
48
|
+
// - Only the primary button; nothing reaches double, middle or right clicks.
|
|
49
|
+
// What a pointer event reports in `button` when no button changed: move, over,
|
|
50
|
+
// out, enter and leave. The compatibility mouse events report 0 instead, as
|
|
51
|
+
// Chrome and Firefox do for real input.
|
|
52
|
+
const NO_BUTTON = -1
|
|
53
|
+
|
|
54
|
+
export class Mouse {
|
|
55
|
+
private element: Element | null = null
|
|
56
|
+
private clientX = 0
|
|
57
|
+
private clientY = 0
|
|
58
|
+
private pressedOn: Element | null = null
|
|
59
|
+
private pointerdownCancelled = false
|
|
60
|
+
|
|
61
|
+
// Moves the pointer to `offset` within the element's client rect, or to its
|
|
62
|
+
// centre.
|
|
63
|
+
move(element: Element, offset?: { x: number; y: number }): void {
|
|
64
|
+
// An element interactable when the move starts gets the whole sequence,
|
|
65
|
+
// even if a handler hides it partway through.
|
|
66
|
+
const interactable = isInteractable(element)
|
|
67
|
+
const rect = getClientRect(element)
|
|
68
|
+
this.clientX = rect.left + (offset ? offset.x : rect.width / 2)
|
|
69
|
+
this.clientY = rect.top + (offset ? offset.y : rect.height / 2)
|
|
70
|
+
|
|
71
|
+
const from = this.element
|
|
72
|
+
if (element !== from) {
|
|
73
|
+
this.transition(from, element, interactable)
|
|
74
|
+
this.element = element
|
|
75
|
+
}
|
|
76
|
+
this.fire(element, EventType.POINTERMOVE, { button: NO_BUTTON, detail: 0 }, interactable)
|
|
77
|
+
this.fire(element, EventType.MOUSEMOVE, { detail: 0 }, interactable)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
pressButton(): void {
|
|
81
|
+
if (this.pressedOn) {
|
|
82
|
+
throw botError(UNKNOWN_ERROR, 'Cannot press more than one button or an already pressed button.')
|
|
83
|
+
}
|
|
84
|
+
const element = this.current()
|
|
85
|
+
this.pressedOn = element
|
|
86
|
+
const interactable = isInteractable(element)
|
|
87
|
+
|
|
88
|
+
this.pointerdownCancelled = !this.fire(element, EventType.POINTERDOWN, { buttons: 1, detail: 0 }, interactable)
|
|
89
|
+
if (this.pointerdownCancelled || !interactable) {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
// Focus is mousedown's default action: cancelling mousedown keeps focus
|
|
93
|
+
// where it was, and so does a handler that moved focus itself.
|
|
94
|
+
const focusedBefore = getActiveElementFrom(element)
|
|
95
|
+
if (this.fire(element, EventType.MOUSEDOWN, { buttons: 1, detail: 1 }, interactable)) {
|
|
96
|
+
if (getActiveElementFrom(element) === focusedBefore) {
|
|
97
|
+
focusOnElement(element)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
releaseButton(): void {
|
|
103
|
+
const pressedOn = this.pressedOn
|
|
104
|
+
if (!pressedOn) {
|
|
105
|
+
throw botError(UNKNOWN_ERROR, 'Cannot release a button when no button is pressed.')
|
|
106
|
+
}
|
|
107
|
+
this.pressedOn = null
|
|
108
|
+
const element = this.current()
|
|
109
|
+
// A mouseup that completes a click is followed by the click even if the
|
|
110
|
+
// mouseup handler made the element non-interactable.
|
|
111
|
+
const interactable = isInteractable(element)
|
|
112
|
+
|
|
113
|
+
this.fire(element, EventType.POINTERUP, { buttons: 0, detail: 0 }, interactable)
|
|
114
|
+
if (!this.pointerdownCancelled) {
|
|
115
|
+
this.fire(element, EventType.MOUSEUP, { buttons: 0, detail: 1 }, interactable)
|
|
116
|
+
}
|
|
117
|
+
const clickTarget = commonAncestor(pressedOn, element)
|
|
118
|
+
if (clickTarget) {
|
|
119
|
+
this.fire(clickTarget, EventType.CLICK, { buttons: 0, detail: 1 }, interactable)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private current(): Element {
|
|
124
|
+
if (!this.element) {
|
|
125
|
+
throw botError(UNKNOWN_ERROR, 'The mouse has not been moved to an element.')
|
|
126
|
+
}
|
|
127
|
+
return this.element
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// out/leave from the old element and over/enter into the new, pointer events
|
|
131
|
+
// first. Enter and leave go to each element whose subtree the pointer
|
|
132
|
+
// entered or left: every ancestor below the common one. The first move
|
|
133
|
+
// treats the pointer as already over the document, so it enters from the
|
|
134
|
+
// body rather than from outside the window.
|
|
135
|
+
private transition(from: Element | null, to: Element, interactable: boolean): void {
|
|
136
|
+
const fromWindowOpen = from && !(from.ownerDocument.defaultView as Window | null)?.closed
|
|
137
|
+
const source = fromWindowOpen ? from : null
|
|
138
|
+
const common = source ? commonAncestor(source, to) : to.ownerDocument.body
|
|
139
|
+
const left = source ? chain(source, common) : []
|
|
140
|
+
const entered = chain(to, common).reverse()
|
|
141
|
+
|
|
142
|
+
const pairs: Array<
|
|
143
|
+
[EventFactory<PointerArgs>, EventFactory<PointerArgs>, EventFactory<PointerArgs>, EventFactory<PointerArgs>, number]
|
|
144
|
+
> = [
|
|
145
|
+
[EventType.POINTEROUT, EventType.POINTERLEAVE, EventType.POINTEROVER, EventType.POINTERENTER, NO_BUTTON],
|
|
146
|
+
[EventType.MOUSEOUT, EventType.MOUSELEAVE, EventType.MOUSEOVER, EventType.MOUSEENTER, 0],
|
|
147
|
+
]
|
|
148
|
+
for (const [out, leave, over, enter, button] of pairs) {
|
|
149
|
+
if (source) {
|
|
150
|
+
this.fire(source, out, { relatedTarget: to, button }, true)
|
|
151
|
+
for (const element of left) {
|
|
152
|
+
this.fire(element, leave, { relatedTarget: to, button }, true)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
this.fire(to, over, { relatedTarget: source, button }, interactable)
|
|
156
|
+
for (const element of entered) {
|
|
157
|
+
this.fire(element, enter, { relatedTarget: source, button }, interactable)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Events go only to an element that was interactable at the start of the
|
|
163
|
+
// step; `interactable` carries that decision.
|
|
164
|
+
private fire(
|
|
165
|
+
target: Element,
|
|
166
|
+
type: EventFactory<PointerArgs>,
|
|
167
|
+
args: Partial<PointerArgs>,
|
|
168
|
+
interactable: boolean,
|
|
169
|
+
): boolean {
|
|
170
|
+
if (!interactable) {
|
|
171
|
+
return false
|
|
172
|
+
}
|
|
173
|
+
return fire(target, type, {
|
|
174
|
+
clientX: this.clientX,
|
|
175
|
+
clientY: this.clientY,
|
|
176
|
+
button: 0,
|
|
177
|
+
buttons: this.pressedOn ? 1 : 0,
|
|
178
|
+
...args,
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// The element and its ancestors up to, but not including, `stop`.
|
|
184
|
+
function chain(element: Element, stop: Element | null): Element[] {
|
|
185
|
+
const result: Element[] = []
|
|
186
|
+
for (let node: Element | null = element; node && node !== stop; node = parentInComposedTree(node)) {
|
|
187
|
+
result.push(node)
|
|
188
|
+
}
|
|
189
|
+
return result
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function parentInComposedTree(element: Element): Element | null {
|
|
193
|
+
if (element.parentElement) {
|
|
194
|
+
return element.parentElement
|
|
195
|
+
}
|
|
196
|
+
const root = element.parentNode
|
|
197
|
+
return root instanceof ShadowRoot ? root.host : null
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function commonAncestor(a: Element, b: Element): Element | null {
|
|
201
|
+
const ancestors = new Set<Element>()
|
|
202
|
+
for (let node: Element | null = a; node; node = parentInComposedTree(node)) {
|
|
203
|
+
ancestors.add(node)
|
|
204
|
+
}
|
|
205
|
+
for (let node: Element | null = b; node; node = parentInComposedTree(node)) {
|
|
206
|
+
if (ancestors.has(node)) {
|
|
207
|
+
return node
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return null
|
|
211
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
+
// or more contributor license agreements. See the NOTICE file
|
|
3
|
+
// distributed with this work for additional information
|
|
4
|
+
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
+
// to you under the Apache License, Version 2.0 (the
|
|
6
|
+
// "License"); you may not use this file except in compliance
|
|
7
|
+
// with the License. You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing,
|
|
12
|
+
// software distributed under the License is distributed on an
|
|
13
|
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
// KIND, either express or implied. See the License for the
|
|
15
|
+
// specific language governing permissions and limitations
|
|
16
|
+
// under the License.
|
|
17
|
+
|
|
18
|
+
import { getParentElement } from './element.js'
|
|
19
|
+
import { Coordinate, Rect, RectReader, Region, getClientRect, getClientRegion } from './geometry.js'
|
|
20
|
+
import { getEffectiveStyle } from './style.js'
|
|
21
|
+
|
|
22
|
+
export type OverflowState = 'none' | 'hidden' | 'scroll';
|
|
23
|
+
|
|
24
|
+
// Reading a style is injectable for the same reason reading a rect is:
|
|
25
|
+
// isShownElement memoises both across one call, everyone else wants the plain
|
|
26
|
+
// read. See core/geometry.ts.
|
|
27
|
+
export type StyleReader = (elem: Element, propertyName: string) => string | null;
|
|
28
|
+
|
|
29
|
+
interface OverflowStyles {
|
|
30
|
+
x: string;
|
|
31
|
+
y: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Whether the element -- or the given sub-region of it -- is clipped by an
|
|
35
|
+
// ancestor, and if so whether scrolling could bring it into view.
|
|
36
|
+
//
|
|
37
|
+
// optRegion applies only to the element asked about. The recursive calls that
|
|
38
|
+
// walk up the ancestors deliberately pass no region, matching
|
|
39
|
+
// bot.dom.getOverflowState.
|
|
40
|
+
export function getOverflowState(
|
|
41
|
+
elem: Element,
|
|
42
|
+
optRegion?: Region,
|
|
43
|
+
getStyle: StyleReader = getEffectiveStyle,
|
|
44
|
+
getRect: RectReader = getClientRect,
|
|
45
|
+
): OverflowState {
|
|
46
|
+
var region = getClientRegion(elem, optRegion, getRect)
|
|
47
|
+
var ownerDoc = elem.ownerDocument
|
|
48
|
+
var htmlElem = ownerDoc.documentElement
|
|
49
|
+
var bodyElem = ownerDoc.body
|
|
50
|
+
var htmlOverflowStyle = getStyle(htmlElem, 'overflow') || 'visible'
|
|
51
|
+
var treatAsFixedPosition = false
|
|
52
|
+
|
|
53
|
+
function canBeOverflowed(container: Element, position: string | null): boolean {
|
|
54
|
+
if (container === htmlElem) {
|
|
55
|
+
return true
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
var display = getStyle(container, 'display') || ''
|
|
59
|
+
if (display.indexOf('inline') === 0 || display === 'contents') {
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (position === 'absolute' && getStyle(container, 'position') === 'static') {
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getOverflowParent(current: Element): Element | null {
|
|
71
|
+
var position = getStyle(current, 'position')
|
|
72
|
+
if (position === 'fixed') {
|
|
73
|
+
treatAsFixedPosition = true
|
|
74
|
+
return current === htmlElem ? null : htmlElem
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
var parent = getParentElement(current)
|
|
78
|
+
while (parent && !canBeOverflowed(parent, position)) {
|
|
79
|
+
parent = getParentElement(parent)
|
|
80
|
+
}
|
|
81
|
+
return parent
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function getOverflowStyles(current: Element): OverflowStyles {
|
|
85
|
+
var overflowElem = current
|
|
86
|
+
if (htmlOverflowStyle === 'visible') {
|
|
87
|
+
if (current === htmlElem && bodyElem) {
|
|
88
|
+
overflowElem = bodyElem
|
|
89
|
+
} else if (current === bodyElem) {
|
|
90
|
+
return { x: 'visible', y: 'visible' }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var overflow = {
|
|
95
|
+
x: getStyle(overflowElem, 'overflow-x') || 'visible',
|
|
96
|
+
y: getStyle(overflowElem, 'overflow-y') || 'visible',
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (current === htmlElem) {
|
|
100
|
+
overflow.x = overflow.x === 'visible' ? 'auto' : overflow.x
|
|
101
|
+
overflow.y = overflow.y === 'visible' ? 'auto' : overflow.y
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return overflow
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getScroll(current: Element): Coordinate {
|
|
108
|
+
if (current === htmlElem) {
|
|
109
|
+
return {
|
|
110
|
+
x: ownerDoc.defaultView ? ownerDoc.defaultView.pageXOffset : 0,
|
|
111
|
+
y: ownerDoc.defaultView ? ownerDoc.defaultView.pageYOffset : 0,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { x: current.scrollLeft, y: current.scrollTop }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function overflowStateOf(container: Element): OverflowState {
|
|
119
|
+
return getOverflowState(container, undefined, getStyle, getRect)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
for (var container = getOverflowParent(elem); container; container = getOverflowParent(container)) {
|
|
123
|
+
var containerOverflow = getOverflowStyles(container)
|
|
124
|
+
if (containerOverflow.x === 'visible' && containerOverflow.y === 'visible') {
|
|
125
|
+
continue
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var containerRect: Rect = getRect(container)
|
|
129
|
+
if (containerRect.width === 0 || containerRect.height === 0) {
|
|
130
|
+
return 'hidden'
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
var underflowsX = region.right < containerRect.left
|
|
134
|
+
var underflowsY = region.bottom < containerRect.top
|
|
135
|
+
if ((underflowsX && containerOverflow.x === 'hidden') || (underflowsY && containerOverflow.y === 'hidden')) {
|
|
136
|
+
return 'hidden'
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if ((underflowsX && containerOverflow.x !== 'visible') || (underflowsY && containerOverflow.y !== 'visible')) {
|
|
140
|
+
var containerScroll = getScroll(container)
|
|
141
|
+
var unscrollableX = region.right < containerRect.left - containerScroll.x
|
|
142
|
+
var unscrollableY = region.bottom < containerRect.top - containerScroll.y
|
|
143
|
+
if ((unscrollableX && containerOverflow.x !== 'visible') || (unscrollableY && containerOverflow.y !== 'visible')) {
|
|
144
|
+
return 'hidden'
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return overflowStateOf(container) === 'hidden' ? 'hidden' : 'scroll'
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
var overflowsX = region.left >= containerRect.left + containerRect.width
|
|
151
|
+
var overflowsY = region.top >= containerRect.top + containerRect.height
|
|
152
|
+
if ((overflowsX && containerOverflow.x === 'hidden') || (overflowsY && containerOverflow.y === 'hidden')) {
|
|
153
|
+
return 'hidden'
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if ((overflowsX && containerOverflow.x !== 'visible') || (overflowsY && containerOverflow.y !== 'visible')) {
|
|
157
|
+
if (treatAsFixedPosition) {
|
|
158
|
+
var docScroll = getScroll(container)
|
|
159
|
+
// region.right against scrollHeight is not a transcription slip: the
|
|
160
|
+
// Closure original compares the horizontal edge to the vertical
|
|
161
|
+
// dimension here (dom.js:800) and the ports have always matched it.
|
|
162
|
+
if (region.left >= htmlElem.scrollWidth - docScroll.x || region.right >= htmlElem.scrollHeight - docScroll.y) {
|
|
163
|
+
return 'hidden'
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return overflowStateOf(container) === 'hidden' ? 'hidden' : 'scroll'
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return 'none'
|
|
172
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
+
// or more contributor license agreements. See the NOTICE file
|
|
3
|
+
// distributed with this work for additional information
|
|
4
|
+
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
+
// to you under the Apache License, Version 2.0 (the
|
|
6
|
+
// "License"); you may not use this file except in compliance
|
|
7
|
+
// with the License. You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing,
|
|
12
|
+
// software distributed under the License is distributed on an
|
|
13
|
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
// KIND, either express or implied. See the License for the
|
|
15
|
+
// specific language governing permissions and limitations
|
|
16
|
+
// under the License.
|
|
17
|
+
|
|
18
|
+
import { getParentElement } from './element.js'
|
|
19
|
+
import { Rect, Region, getClientRect, getClientRegion } from './geometry.js'
|
|
20
|
+
import { getOverflowState } from './overflow.js'
|
|
21
|
+
import { getEffectiveStyle } from './style.js'
|
|
22
|
+
|
|
23
|
+
interface Box {
|
|
24
|
+
top: number;
|
|
25
|
+
right: number;
|
|
26
|
+
bottom: number;
|
|
27
|
+
left: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// goog.style.getBorderBox: the computed border widths, which are what separate
|
|
31
|
+
// a container's client rect from its content box.
|
|
32
|
+
function getBorderBox(element: Element): Box {
|
|
33
|
+
const width = (side: string) => parseFloat(getEffectiveStyle(element, 'border-' + side + '-width') || '0') || 0
|
|
34
|
+
return {
|
|
35
|
+
top: width('top'),
|
|
36
|
+
right: width('right'),
|
|
37
|
+
bottom: width('bottom'),
|
|
38
|
+
left: width('left'),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Scrolls the element, or the given sub-region of it, into view and reports
|
|
43
|
+
// whether it ended up visible.
|
|
44
|
+
//
|
|
45
|
+
// This is bot.action.scrollIntoView. It lives in core/ rather than with the
|
|
46
|
+
// interaction atoms because it reaches only geometry and overflow -- never
|
|
47
|
+
// events, keyboard, mouse or device. In Closure it was trapped in action.js's
|
|
48
|
+
// module graph and dragged all of that in with it; per-file imports are what
|
|
49
|
+
// let it come out on its own.
|
|
50
|
+
export function scrollIntoView(element: Element, optRegion?: Region): boolean {
|
|
51
|
+
// Already in view, or clipped beyond rescuing: either way, no scrolling.
|
|
52
|
+
const overflow = getOverflowState(element, optRegion)
|
|
53
|
+
if (overflow !== 'scroll') {
|
|
54
|
+
return overflow === 'none'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Elements under an SVG element may have no scrollIntoView, so only call it
|
|
58
|
+
// where it exists.
|
|
59
|
+
if (typeof (element as HTMLElement).scrollIntoView === 'function') {
|
|
60
|
+
;(element as HTMLElement).scrollIntoView()
|
|
61
|
+
if (getOverflowState(element, optRegion) === 'none') {
|
|
62
|
+
return true
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Either there was no scrollIntoView, or it did not bring the requested
|
|
67
|
+
// coordinate into view, so scroll each ancestor by hand.
|
|
68
|
+
const region = getClientRegion(element, optRegion)
|
|
69
|
+
for (let container = getParentElement(element); container; container = getParentElement(container)) {
|
|
70
|
+
scrollRegionIntoContainerView(region, container)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return getOverflowState(element, optRegion) === 'none'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Based largely on goog.style.scrollIntoContainerView.
|
|
77
|
+
function scrollRegionIntoContainerView(region: Rect, container: Element): void {
|
|
78
|
+
const containerRect = getClientRect(container)
|
|
79
|
+
const containerBorder = getBorderBox(container)
|
|
80
|
+
|
|
81
|
+
// Position of the region relative to the container's content box.
|
|
82
|
+
const relX = region.left - containerRect.left - containerBorder.left
|
|
83
|
+
const relY = region.top - containerRect.top - containerBorder.top
|
|
84
|
+
|
|
85
|
+
// How far the region can move inside the container. clientWidth/Height
|
|
86
|
+
// rather than the rect, so the scrollbar is accounted for.
|
|
87
|
+
const spaceX = container.clientWidth + region.left - region.right
|
|
88
|
+
const spaceY = container.clientHeight + region.top - region.bottom
|
|
89
|
+
|
|
90
|
+
container.scrollLeft += Math.min(relX, Math.max(relX - spaceX, 0))
|
|
91
|
+
container.scrollTop += Math.min(relY, Math.max(relY - spaceY, 0))
|
|
92
|
+
}
|