You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
690 B
28 lines
690 B
|
3 years ago
|
"use strict";
|
||
|
|
const NODE_TYPE = require("../node-type");
|
||
|
|
const { getRoot, retarget } = require("../helpers/shadow-dom");
|
||
|
|
|
||
|
|
class DocumentOrShadowRootImpl {
|
||
|
|
get activeElement() {
|
||
|
|
let candidate = this._ownerDocument._lastFocusedElement || this._ownerDocument.body;
|
||
|
|
if (!candidate) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
candidate = retarget(candidate, this);
|
||
|
|
if (getRoot(candidate) !== this) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
if (candidate.nodeType !== NODE_TYPE.DOCUMENT_NODE) {
|
||
|
|
return candidate;
|
||
|
|
}
|
||
|
|
if (candidate.body !== null) {
|
||
|
|
return candidate.body;
|
||
|
|
}
|
||
|
|
return candidate.documentElement;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = {
|
||
|
|
implementation: DocumentOrShadowRootImpl
|
||
|
|
};
|