@react-aria/utils 3.27.0 → 3.28.1
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/dist/DOMFunctions.main.js +44 -0
- package/dist/DOMFunctions.main.js.map +1 -0
- package/dist/DOMFunctions.mjs +37 -0
- package/dist/DOMFunctions.module.js +37 -0
- package/dist/DOMFunctions.module.js.map +1 -0
- package/dist/ShadowTreeWalker.main.js +200 -0
- package/dist/ShadowTreeWalker.main.js.map +1 -0
- package/dist/ShadowTreeWalker.mjs +194 -0
- package/dist/ShadowTreeWalker.module.js +194 -0
- package/dist/ShadowTreeWalker.module.js.map +1 -0
- package/dist/constants.main.js +0 -2
- package/dist/constants.main.js.map +1 -1
- package/dist/constants.mjs +1 -2
- package/dist/constants.module.js +1 -2
- package/dist/constants.module.js.map +1 -1
- package/dist/domHelpers.main.js +9 -0
- package/dist/domHelpers.main.js.map +1 -1
- package/dist/domHelpers.mjs +9 -1
- package/dist/domHelpers.module.js +9 -1
- package/dist/domHelpers.module.js.map +1 -1
- package/dist/import.mjs +11 -3
- package/dist/inertValue.main.js +19 -0
- package/dist/inertValue.main.js.map +1 -0
- package/dist/inertValue.mjs +14 -0
- package/dist/inertValue.module.js +14 -0
- package/dist/inertValue.module.js.map +1 -0
- package/dist/isFocusable.main.js +34 -0
- package/dist/isFocusable.main.js.map +1 -0
- package/dist/isFocusable.mjs +28 -0
- package/dist/isFocusable.module.js +28 -0
- package/dist/isFocusable.module.js.map +1 -0
- package/dist/main.js +17 -1
- package/dist/main.js.map +1 -1
- package/dist/mergeProps.main.js.map +1 -1
- package/dist/mergeProps.module.js.map +1 -1
- package/dist/module.js +11 -3
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +50 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useGlobalListeners.main.js.map +1 -1
- package/dist/useGlobalListeners.module.js.map +1 -1
- package/dist/useId.main.js +27 -21
- package/dist/useId.main.js.map +1 -1
- package/dist/useId.mjs +29 -23
- package/dist/useId.module.js +29 -23
- package/dist/useId.module.js.map +1 -1
- package/dist/useUpdateEffect.main.js +2 -1
- package/dist/useUpdateEffect.main.js.map +1 -1
- package/dist/useUpdateEffect.mjs +2 -1
- package/dist/useUpdateEffect.module.js +2 -1
- package/dist/useUpdateEffect.module.js.map +1 -1
- package/package.json +4 -3
- package/src/constants.ts +0 -1
- package/src/domHelpers.ts +19 -0
- package/src/index.ts +6 -2
- package/src/inertValue.ts +11 -0
- package/src/isFocusable.ts +28 -0
- package/src/mergeProps.ts +1 -1
- package/src/shadowdom/DOMFunctions.ts +70 -0
- package/src/shadowdom/ShadowTreeWalker.ts +319 -0
- package/src/useGlobalListeners.ts +1 -0
- package/src/useId.ts +31 -15
- package/src/useUpdateEffect.ts +3 -2
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var $aaa611146751592e$exports = require("./domHelpers.main.js");
|
|
2
|
+
var $loak6$reactstatelyflags = require("@react-stately/flags");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "nodeContains", () => $d723bea02f3e2567$export$4282f70798064fe0);
|
|
10
|
+
$parcel$export(module.exports, "getActiveElement", () => $d723bea02f3e2567$export$cd4e5573fbe2b576);
|
|
11
|
+
$parcel$export(module.exports, "getEventTarget", () => $d723bea02f3e2567$export$e58f029f0fbfdb29);
|
|
12
|
+
// Source: https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/DOMFunctions.ts#L16
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
function $d723bea02f3e2567$export$4282f70798064fe0(node, otherNode) {
|
|
16
|
+
if (!(0, $loak6$reactstatelyflags.shadowDOM)()) return otherNode && node ? node.contains(otherNode) : false;
|
|
17
|
+
if (!node || !otherNode) return false;
|
|
18
|
+
let currentNode = otherNode;
|
|
19
|
+
while(currentNode !== null){
|
|
20
|
+
if (currentNode === node) return true;
|
|
21
|
+
if (currentNode.tagName === 'SLOT' && currentNode.assignedSlot) // Element is slotted
|
|
22
|
+
currentNode = currentNode.assignedSlot.parentNode;
|
|
23
|
+
else if ((0, $aaa611146751592e$exports.isShadowRoot)(currentNode)) // Element is in shadow root
|
|
24
|
+
currentNode = currentNode.host;
|
|
25
|
+
else currentNode = currentNode.parentNode;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const $d723bea02f3e2567$export$cd4e5573fbe2b576 = (doc = document)=>{
|
|
30
|
+
var _activeElement_shadowRoot;
|
|
31
|
+
if (!(0, $loak6$reactstatelyflags.shadowDOM)()) return doc.activeElement;
|
|
32
|
+
let activeElement = doc.activeElement;
|
|
33
|
+
while(activeElement && 'shadowRoot' in activeElement && ((_activeElement_shadowRoot = activeElement.shadowRoot) === null || _activeElement_shadowRoot === void 0 ? void 0 : _activeElement_shadowRoot.activeElement))activeElement = activeElement.shadowRoot.activeElement;
|
|
34
|
+
return activeElement;
|
|
35
|
+
};
|
|
36
|
+
function $d723bea02f3e2567$export$e58f029f0fbfdb29(event) {
|
|
37
|
+
if ((0, $loak6$reactstatelyflags.shadowDOM)() && event.target.shadowRoot) {
|
|
38
|
+
if (event.composedPath) return event.composedPath()[0];
|
|
39
|
+
}
|
|
40
|
+
return event.target;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=DOMFunctions.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA,kIAAkI;;;AAQ3H,SAAS,0CACd,IAA6B,EAC7B,SAAkC;IAElC,IAAI,CAAC,CAAA,GAAA,kCAAQ,KACX,OAAO,aAAa,OAAO,KAAK,QAAQ,CAAC,aAAa;IAGxD,IAAI,CAAC,QAAQ,CAAC,WACZ,OAAO;IAGT,IAAI,cAAqD;IAEzD,MAAO,gBAAgB,KAAM;QAC3B,IAAI,gBAAgB,MAClB,OAAO;QAGT,IAAI,AAAC,YAAgC,OAAO,KAAK,UAC/C,AAAC,YAAgC,YAAY,EAC7C,qBAAqB;QACrB,cAAc,AAAC,YAAgC,YAAY,CAAE,UAAU;aAClE,IAAI,CAAA,GAAA,sCAAW,EAAE,cACtB,4BAA4B;QAC5B,cAAc,YAAY,IAAI;aAE9B,cAAc,YAAY,UAAU;IAExC;IAEA,OAAO;AACT;AAKO,MAAM,4CAAmB,CAAC,MAAgB,QAAQ;QAOvD;IANA,IAAI,CAAC,CAAA,GAAA,kCAAQ,KACX,OAAO,IAAI,aAAa;IAE1B,IAAI,gBAAgC,IAAI,aAAa;IAErD,MAAO,iBAAiB,gBAAgB,mBACxC,4BAAA,cAAc,UAAU,cAAxB,gDAAA,0BAA0B,aAAa,EACrC,gBAAgB,cAAc,UAAU,CAAC,aAAa;IAGxD,OAAO;AACT;AAKO,SAAS,0CAAe,KAAK;IAClC,IAAI,CAAA,GAAA,kCAAQ,OAAO,MAAM,MAAM,CAAC,UAAU,EAAE;QAC1C,IAAI,MAAM,YAAY,EACpB,OAAO,MAAM,YAAY,EAAE,CAAC,EAAE;IAElC;IACA,OAAO,MAAM,MAAM;AACrB","sources":["packages/@react-aria/utils/src/shadowdom/DOMFunctions.ts"],"sourcesContent":["// Source: https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/DOMFunctions.ts#L16\n\nimport {isShadowRoot} from '../domHelpers';\nimport {shadowDOM} from '@react-stately/flags';\n\n/**\n * ShadowDOM safe version of Node.contains.\n */\nexport function nodeContains(\n node: Node | null | undefined,\n otherNode: Node | null | undefined\n): boolean {\n if (!shadowDOM()) {\n return otherNode && node ? node.contains(otherNode) : false;\n }\n\n if (!node || !otherNode) {\n return false;\n }\n\n let currentNode: HTMLElement | Node | null | undefined = otherNode;\n\n while (currentNode !== null) {\n if (currentNode === node) {\n return true;\n }\n\n if ((currentNode as HTMLSlotElement).tagName === 'SLOT' &&\n (currentNode as HTMLSlotElement).assignedSlot) {\n // Element is slotted\n currentNode = (currentNode as HTMLSlotElement).assignedSlot!.parentNode;\n } else if (isShadowRoot(currentNode)) {\n // Element is in shadow root\n currentNode = currentNode.host;\n } else {\n currentNode = currentNode.parentNode;\n }\n }\n\n return false;\n}\n\n/**\n * ShadowDOM safe version of document.activeElement.\n */\nexport const getActiveElement = (doc: Document = document) => {\n if (!shadowDOM()) {\n return doc.activeElement;\n }\n let activeElement: Element | null = doc.activeElement;\n\n while (activeElement && 'shadowRoot' in activeElement &&\n activeElement.shadowRoot?.activeElement) {\n activeElement = activeElement.shadowRoot.activeElement;\n }\n\n return activeElement;\n};\n\n/**\n * ShadowDOM safe version of event.target.\n */\nexport function getEventTarget(event): Element {\n if (shadowDOM() && event.target.shadowRoot) {\n if (event.composedPath) {\n return event.composedPath()[0];\n }\n }\n return event.target;\n}\n"],"names":[],"version":3,"file":"DOMFunctions.main.js.map"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {isShadowRoot as $431fbd86ca7dc216$export$af51f0f06c0f328a} from "./domHelpers.mjs";
|
|
2
|
+
import {shadowDOM as $lcSu5$shadowDOM} from "@react-stately/flags";
|
|
3
|
+
|
|
4
|
+
// Source: https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/DOMFunctions.ts#L16
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function $d4ee10de306f2510$export$4282f70798064fe0(node, otherNode) {
|
|
8
|
+
if (!(0, $lcSu5$shadowDOM)()) return otherNode && node ? node.contains(otherNode) : false;
|
|
9
|
+
if (!node || !otherNode) return false;
|
|
10
|
+
let currentNode = otherNode;
|
|
11
|
+
while(currentNode !== null){
|
|
12
|
+
if (currentNode === node) return true;
|
|
13
|
+
if (currentNode.tagName === 'SLOT' && currentNode.assignedSlot) // Element is slotted
|
|
14
|
+
currentNode = currentNode.assignedSlot.parentNode;
|
|
15
|
+
else if ((0, $431fbd86ca7dc216$export$af51f0f06c0f328a)(currentNode)) // Element is in shadow root
|
|
16
|
+
currentNode = currentNode.host;
|
|
17
|
+
else currentNode = currentNode.parentNode;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const $d4ee10de306f2510$export$cd4e5573fbe2b576 = (doc = document)=>{
|
|
22
|
+
var _activeElement_shadowRoot;
|
|
23
|
+
if (!(0, $lcSu5$shadowDOM)()) return doc.activeElement;
|
|
24
|
+
let activeElement = doc.activeElement;
|
|
25
|
+
while(activeElement && 'shadowRoot' in activeElement && ((_activeElement_shadowRoot = activeElement.shadowRoot) === null || _activeElement_shadowRoot === void 0 ? void 0 : _activeElement_shadowRoot.activeElement))activeElement = activeElement.shadowRoot.activeElement;
|
|
26
|
+
return activeElement;
|
|
27
|
+
};
|
|
28
|
+
function $d4ee10de306f2510$export$e58f029f0fbfdb29(event) {
|
|
29
|
+
if ((0, $lcSu5$shadowDOM)() && event.target.shadowRoot) {
|
|
30
|
+
if (event.composedPath) return event.composedPath()[0];
|
|
31
|
+
}
|
|
32
|
+
return event.target;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export {$d4ee10de306f2510$export$4282f70798064fe0 as nodeContains, $d4ee10de306f2510$export$cd4e5573fbe2b576 as getActiveElement, $d4ee10de306f2510$export$e58f029f0fbfdb29 as getEventTarget};
|
|
37
|
+
//# sourceMappingURL=DOMFunctions.module.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {isShadowRoot as $431fbd86ca7dc216$export$af51f0f06c0f328a} from "./domHelpers.module.js";
|
|
2
|
+
import {shadowDOM as $lcSu5$shadowDOM} from "@react-stately/flags";
|
|
3
|
+
|
|
4
|
+
// Source: https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/DOMFunctions.ts#L16
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function $d4ee10de306f2510$export$4282f70798064fe0(node, otherNode) {
|
|
8
|
+
if (!(0, $lcSu5$shadowDOM)()) return otherNode && node ? node.contains(otherNode) : false;
|
|
9
|
+
if (!node || !otherNode) return false;
|
|
10
|
+
let currentNode = otherNode;
|
|
11
|
+
while(currentNode !== null){
|
|
12
|
+
if (currentNode === node) return true;
|
|
13
|
+
if (currentNode.tagName === 'SLOT' && currentNode.assignedSlot) // Element is slotted
|
|
14
|
+
currentNode = currentNode.assignedSlot.parentNode;
|
|
15
|
+
else if ((0, $431fbd86ca7dc216$export$af51f0f06c0f328a)(currentNode)) // Element is in shadow root
|
|
16
|
+
currentNode = currentNode.host;
|
|
17
|
+
else currentNode = currentNode.parentNode;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const $d4ee10de306f2510$export$cd4e5573fbe2b576 = (doc = document)=>{
|
|
22
|
+
var _activeElement_shadowRoot;
|
|
23
|
+
if (!(0, $lcSu5$shadowDOM)()) return doc.activeElement;
|
|
24
|
+
let activeElement = doc.activeElement;
|
|
25
|
+
while(activeElement && 'shadowRoot' in activeElement && ((_activeElement_shadowRoot = activeElement.shadowRoot) === null || _activeElement_shadowRoot === void 0 ? void 0 : _activeElement_shadowRoot.activeElement))activeElement = activeElement.shadowRoot.activeElement;
|
|
26
|
+
return activeElement;
|
|
27
|
+
};
|
|
28
|
+
function $d4ee10de306f2510$export$e58f029f0fbfdb29(event) {
|
|
29
|
+
if ((0, $lcSu5$shadowDOM)() && event.target.shadowRoot) {
|
|
30
|
+
if (event.composedPath) return event.composedPath()[0];
|
|
31
|
+
}
|
|
32
|
+
return event.target;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export {$d4ee10de306f2510$export$4282f70798064fe0 as nodeContains, $d4ee10de306f2510$export$cd4e5573fbe2b576 as getActiveElement, $d4ee10de306f2510$export$e58f029f0fbfdb29 as getEventTarget};
|
|
37
|
+
//# sourceMappingURL=DOMFunctions.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA,kIAAkI;;;AAQ3H,SAAS,0CACd,IAA6B,EAC7B,SAAkC;IAElC,IAAI,CAAC,CAAA,GAAA,gBAAQ,KACX,OAAO,aAAa,OAAO,KAAK,QAAQ,CAAC,aAAa;IAGxD,IAAI,CAAC,QAAQ,CAAC,WACZ,OAAO;IAGT,IAAI,cAAqD;IAEzD,MAAO,gBAAgB,KAAM;QAC3B,IAAI,gBAAgB,MAClB,OAAO;QAGT,IAAI,AAAC,YAAgC,OAAO,KAAK,UAC/C,AAAC,YAAgC,YAAY,EAC7C,qBAAqB;QACrB,cAAc,AAAC,YAAgC,YAAY,CAAE,UAAU;aAClE,IAAI,CAAA,GAAA,yCAAW,EAAE,cACtB,4BAA4B;QAC5B,cAAc,YAAY,IAAI;aAE9B,cAAc,YAAY,UAAU;IAExC;IAEA,OAAO;AACT;AAKO,MAAM,4CAAmB,CAAC,MAAgB,QAAQ;QAOvD;IANA,IAAI,CAAC,CAAA,GAAA,gBAAQ,KACX,OAAO,IAAI,aAAa;IAE1B,IAAI,gBAAgC,IAAI,aAAa;IAErD,MAAO,iBAAiB,gBAAgB,mBACxC,4BAAA,cAAc,UAAU,cAAxB,gDAAA,0BAA0B,aAAa,EACrC,gBAAgB,cAAc,UAAU,CAAC,aAAa;IAGxD,OAAO;AACT;AAKO,SAAS,0CAAe,KAAK;IAClC,IAAI,CAAA,GAAA,gBAAQ,OAAO,MAAM,MAAM,CAAC,UAAU,EAAE;QAC1C,IAAI,MAAM,YAAY,EACpB,OAAO,MAAM,YAAY,EAAE,CAAC,EAAE;IAElC;IACA,OAAO,MAAM,MAAM;AACrB","sources":["packages/@react-aria/utils/src/shadowdom/DOMFunctions.ts"],"sourcesContent":["// Source: https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/DOMFunctions.ts#L16\n\nimport {isShadowRoot} from '../domHelpers';\nimport {shadowDOM} from '@react-stately/flags';\n\n/**\n * ShadowDOM safe version of Node.contains.\n */\nexport function nodeContains(\n node: Node | null | undefined,\n otherNode: Node | null | undefined\n): boolean {\n if (!shadowDOM()) {\n return otherNode && node ? node.contains(otherNode) : false;\n }\n\n if (!node || !otherNode) {\n return false;\n }\n\n let currentNode: HTMLElement | Node | null | undefined = otherNode;\n\n while (currentNode !== null) {\n if (currentNode === node) {\n return true;\n }\n\n if ((currentNode as HTMLSlotElement).tagName === 'SLOT' &&\n (currentNode as HTMLSlotElement).assignedSlot) {\n // Element is slotted\n currentNode = (currentNode as HTMLSlotElement).assignedSlot!.parentNode;\n } else if (isShadowRoot(currentNode)) {\n // Element is in shadow root\n currentNode = currentNode.host;\n } else {\n currentNode = currentNode.parentNode;\n }\n }\n\n return false;\n}\n\n/**\n * ShadowDOM safe version of document.activeElement.\n */\nexport const getActiveElement = (doc: Document = document) => {\n if (!shadowDOM()) {\n return doc.activeElement;\n }\n let activeElement: Element | null = doc.activeElement;\n\n while (activeElement && 'shadowRoot' in activeElement &&\n activeElement.shadowRoot?.activeElement) {\n activeElement = activeElement.shadowRoot.activeElement;\n }\n\n return activeElement;\n};\n\n/**\n * ShadowDOM safe version of event.target.\n */\nexport function getEventTarget(event): Element {\n if (shadowDOM() && event.target.shadowRoot) {\n if (event.composedPath) {\n return event.composedPath()[0];\n }\n }\n return event.target;\n}\n"],"names":[],"version":3,"file":"DOMFunctions.module.js.map"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
var $d723bea02f3e2567$exports = require("./DOMFunctions.main.js");
|
|
2
|
+
var $hdE3O$reactstatelyflags = require("@react-stately/flags");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "ShadowTreeWalker", () => $8e13b2545651735a$export$63eb3ababa9c55c4);
|
|
10
|
+
$parcel$export(module.exports, "createShadowTreeWalker", () => $8e13b2545651735a$export$4d0f8be8b12a7ef6);
|
|
11
|
+
// https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/ShadowTreeWalker.ts
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class $8e13b2545651735a$export$63eb3ababa9c55c4 {
|
|
15
|
+
get currentNode() {
|
|
16
|
+
return this._currentNode;
|
|
17
|
+
}
|
|
18
|
+
set currentNode(node) {
|
|
19
|
+
if (!(0, $d723bea02f3e2567$exports.nodeContains)(this.root, node)) throw new Error('Cannot set currentNode to a node that is not contained by the root node.');
|
|
20
|
+
const walkers = [];
|
|
21
|
+
let curNode = node;
|
|
22
|
+
let currentWalkerCurrentNode = node;
|
|
23
|
+
this._currentNode = node;
|
|
24
|
+
while(curNode && curNode !== this.root)if (curNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
25
|
+
const shadowRoot = curNode;
|
|
26
|
+
const walker = this._doc.createTreeWalker(shadowRoot, this.whatToShow, {
|
|
27
|
+
acceptNode: this._acceptNode
|
|
28
|
+
});
|
|
29
|
+
walkers.push(walker);
|
|
30
|
+
walker.currentNode = currentWalkerCurrentNode;
|
|
31
|
+
this._currentSetFor.add(walker);
|
|
32
|
+
curNode = currentWalkerCurrentNode = shadowRoot.host;
|
|
33
|
+
} else curNode = curNode.parentNode;
|
|
34
|
+
const walker = this._doc.createTreeWalker(this.root, this.whatToShow, {
|
|
35
|
+
acceptNode: this._acceptNode
|
|
36
|
+
});
|
|
37
|
+
walkers.push(walker);
|
|
38
|
+
walker.currentNode = currentWalkerCurrentNode;
|
|
39
|
+
this._currentSetFor.add(walker);
|
|
40
|
+
this._walkerStack = walkers;
|
|
41
|
+
}
|
|
42
|
+
get doc() {
|
|
43
|
+
return this._doc;
|
|
44
|
+
}
|
|
45
|
+
firstChild() {
|
|
46
|
+
let currentNode = this.currentNode;
|
|
47
|
+
let newNode = this.nextNode();
|
|
48
|
+
if (!(0, $d723bea02f3e2567$exports.nodeContains)(currentNode, newNode)) {
|
|
49
|
+
this.currentNode = currentNode;
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (newNode) this.currentNode = newNode;
|
|
53
|
+
return newNode;
|
|
54
|
+
}
|
|
55
|
+
lastChild() {
|
|
56
|
+
let walker = this._walkerStack[0];
|
|
57
|
+
let newNode = walker.lastChild();
|
|
58
|
+
if (newNode) this.currentNode = newNode;
|
|
59
|
+
return newNode;
|
|
60
|
+
}
|
|
61
|
+
nextNode() {
|
|
62
|
+
const nextNode = this._walkerStack[0].nextNode();
|
|
63
|
+
if (nextNode) {
|
|
64
|
+
const shadowRoot = nextNode.shadowRoot;
|
|
65
|
+
if (shadowRoot) {
|
|
66
|
+
var _this_filter;
|
|
67
|
+
let nodeResult;
|
|
68
|
+
if (typeof this.filter === 'function') nodeResult = this.filter(nextNode);
|
|
69
|
+
else if ((_this_filter = this.filter) === null || _this_filter === void 0 ? void 0 : _this_filter.acceptNode) nodeResult = this.filter.acceptNode(nextNode);
|
|
70
|
+
if (nodeResult === NodeFilter.FILTER_ACCEPT) {
|
|
71
|
+
this.currentNode = nextNode;
|
|
72
|
+
return nextNode;
|
|
73
|
+
}
|
|
74
|
+
// _acceptNode should have added new walker for this shadow,
|
|
75
|
+
// go in recursively.
|
|
76
|
+
let newNode = this.nextNode();
|
|
77
|
+
if (newNode) this.currentNode = newNode;
|
|
78
|
+
return newNode;
|
|
79
|
+
}
|
|
80
|
+
if (nextNode) this.currentNode = nextNode;
|
|
81
|
+
return nextNode;
|
|
82
|
+
} else {
|
|
83
|
+
if (this._walkerStack.length > 1) {
|
|
84
|
+
this._walkerStack.shift();
|
|
85
|
+
let newNode = this.nextNode();
|
|
86
|
+
if (newNode) this.currentNode = newNode;
|
|
87
|
+
return newNode;
|
|
88
|
+
} else return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
previousNode() {
|
|
92
|
+
const currentWalker = this._walkerStack[0];
|
|
93
|
+
if (currentWalker.currentNode === currentWalker.root) {
|
|
94
|
+
if (this._currentSetFor.has(currentWalker)) {
|
|
95
|
+
this._currentSetFor.delete(currentWalker);
|
|
96
|
+
if (this._walkerStack.length > 1) {
|
|
97
|
+
this._walkerStack.shift();
|
|
98
|
+
let newNode = this.previousNode();
|
|
99
|
+
if (newNode) this.currentNode = newNode;
|
|
100
|
+
return newNode;
|
|
101
|
+
} else return null;
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const previousNode = currentWalker.previousNode();
|
|
106
|
+
if (previousNode) {
|
|
107
|
+
const shadowRoot = previousNode.shadowRoot;
|
|
108
|
+
if (shadowRoot) {
|
|
109
|
+
var _this_filter;
|
|
110
|
+
let nodeResult;
|
|
111
|
+
if (typeof this.filter === 'function') nodeResult = this.filter(previousNode);
|
|
112
|
+
else if ((_this_filter = this.filter) === null || _this_filter === void 0 ? void 0 : _this_filter.acceptNode) nodeResult = this.filter.acceptNode(previousNode);
|
|
113
|
+
if (nodeResult === NodeFilter.FILTER_ACCEPT) {
|
|
114
|
+
if (previousNode) this.currentNode = previousNode;
|
|
115
|
+
return previousNode;
|
|
116
|
+
}
|
|
117
|
+
// _acceptNode should have added new walker for this shadow,
|
|
118
|
+
// go in recursively.
|
|
119
|
+
let newNode = this.lastChild();
|
|
120
|
+
if (newNode) this.currentNode = newNode;
|
|
121
|
+
return newNode;
|
|
122
|
+
}
|
|
123
|
+
if (previousNode) this.currentNode = previousNode;
|
|
124
|
+
return previousNode;
|
|
125
|
+
} else {
|
|
126
|
+
if (this._walkerStack.length > 1) {
|
|
127
|
+
this._walkerStack.shift();
|
|
128
|
+
let newNode = this.previousNode();
|
|
129
|
+
if (newNode) this.currentNode = newNode;
|
|
130
|
+
return newNode;
|
|
131
|
+
} else return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @deprecated
|
|
136
|
+
*/ nextSibling() {
|
|
137
|
+
// if (__DEV__) {
|
|
138
|
+
// throw new Error("Method not implemented.");
|
|
139
|
+
// }
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @deprecated
|
|
144
|
+
*/ previousSibling() {
|
|
145
|
+
// if (__DEV__) {
|
|
146
|
+
// throw new Error("Method not implemented.");
|
|
147
|
+
// }
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @deprecated
|
|
152
|
+
*/ parentNode() {
|
|
153
|
+
// if (__DEV__) {
|
|
154
|
+
// throw new Error("Method not implemented.");
|
|
155
|
+
// }
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
constructor(doc, root, whatToShow, filter){
|
|
159
|
+
this._walkerStack = [];
|
|
160
|
+
this._currentSetFor = new Set();
|
|
161
|
+
this._acceptNode = (node)=>{
|
|
162
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
163
|
+
const shadowRoot = node.shadowRoot;
|
|
164
|
+
if (shadowRoot) {
|
|
165
|
+
const walker = this._doc.createTreeWalker(shadowRoot, this.whatToShow, {
|
|
166
|
+
acceptNode: this._acceptNode
|
|
167
|
+
});
|
|
168
|
+
this._walkerStack.unshift(walker);
|
|
169
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
170
|
+
} else {
|
|
171
|
+
var _this_filter;
|
|
172
|
+
if (typeof this.filter === 'function') return this.filter(node);
|
|
173
|
+
else if ((_this_filter = this.filter) === null || _this_filter === void 0 ? void 0 : _this_filter.acceptNode) return this.filter.acceptNode(node);
|
|
174
|
+
else if (this.filter === null) return NodeFilter.FILTER_ACCEPT;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return NodeFilter.FILTER_SKIP;
|
|
178
|
+
};
|
|
179
|
+
this._doc = doc;
|
|
180
|
+
this.root = root;
|
|
181
|
+
this.filter = filter !== null && filter !== void 0 ? filter : null;
|
|
182
|
+
this.whatToShow = whatToShow !== null && whatToShow !== void 0 ? whatToShow : NodeFilter.SHOW_ALL;
|
|
183
|
+
this._currentNode = root;
|
|
184
|
+
this._walkerStack.unshift(doc.createTreeWalker(root, whatToShow, this._acceptNode));
|
|
185
|
+
const shadowRoot = root.shadowRoot;
|
|
186
|
+
if (shadowRoot) {
|
|
187
|
+
const walker = this._doc.createTreeWalker(shadowRoot, this.whatToShow, {
|
|
188
|
+
acceptNode: this._acceptNode
|
|
189
|
+
});
|
|
190
|
+
this._walkerStack.unshift(walker);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function $8e13b2545651735a$export$4d0f8be8b12a7ef6(doc, root, whatToShow, filter) {
|
|
195
|
+
if ((0, $hdE3O$reactstatelyflags.shadowDOM)()) return new $8e13b2545651735a$export$63eb3ababa9c55c4(doc, root, whatToShow, filter);
|
|
196
|
+
return doc.createTreeWalker(root, whatToShow, filter);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
//# sourceMappingURL=ShadowTreeWalker.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA,0HAA0H;;;AAKnH,MAAM;IAmEX,IAAW,cAAoB;QAC7B,OAAO,IAAI,CAAC,YAAY;IAC1B;IAEA,IAAW,YAAY,IAAU,EAAE;QACjC,IAAI,CAAC,CAAA,GAAA,sCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,OAC3B,MAAM,IAAI,MACR;QAIJ,MAAM,UAAwB,EAAE;QAChC,IAAI,UAAmC;QACvC,IAAI,2BAA2B;QAE/B,IAAI,CAAC,YAAY,GAAG;QAEpB,MAAO,WAAW,YAAY,IAAI,CAAC,IAAI,CACrC,IAAI,QAAQ,QAAQ,KAAK,KAAK,sBAAsB,EAAE;YACpD,MAAM,aAAa;YAEnB,MAAM,SAAS,IAAI,CAAC,IAAI,CAAC,gBAAg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344489d1c3898/src/Shadowdomize/ShadowTreeWalker.ts\n\nimport {nodeContains} from './DOMFunctions';\nimport {shadowDOM} from '@react-stately/flags';\n\nexport class ShadowTreeWalker implements TreeWalker {\n public readonly filter: NodeFilter | null;\n public readonly root: Node;\n public readonly whatToShow: number;\n\n private _doc: Document;\n private _walkerStack: Array<TreeWalker> = [];\n private _currentNode: Node;\n private _currentSetFor: Set<TreeWalker> = new Set();\n\n constructor(\n doc: Document,\n root: Node,\n whatToShow?: number,\n filter?: NodeFilter | null\n ) {\n this._doc = doc;\n this.root = root;\n this.filter = filter ?? null;\n this.whatToShow = whatToShow ?? NodeFilter.SHOW_ALL;\n this._currentNode = root;\n\n this._walkerStack.unshift(\n doc.createTreeWalker(root, whatToShow, this._acceptNode)\n );\n\n const shadowRoot = (root as Element).shadowRoot;\n\n if (shadowRoot) {\n const walker = this._doc.createTreeWalker(\n shadowRoot,\n this.whatToShow,\n {acceptNode: this._acceptNode}\n );\n\n this._walkerStack.unshift(walker);\n }\n }\n\n private _acceptNode = (node: Node): number => {\n if (node.nodeType === Node.ELEMENT_NODE) {\n const shadowRoot = (node as Element).shadowRoot;\n\n if (shadowRoot) {\n const walker = this._doc.createTreeWalker(\n shadowRoot,\n this.whatToShow,\n {acceptNode: this._acceptNode}\n );\n\n this._walkerStack.unshift(walker);\n\n return NodeFilter.FILTER_ACCEPT;\n } else {\n if (typeof this.filter === 'function') {\n return this.filter(node);\n } else if (this.filter?.acceptNode) {\n return this.filter.acceptNode(node);\n } else if (this.filter === null) {\n return NodeFilter.FILTER_ACCEPT;\n }\n }\n }\n\n return NodeFilter.FILTER_SKIP;\n };\n\n public get currentNode(): Node {\n return this._currentNode;\n }\n\n public set currentNode(node: Node) {\n if (!nodeContains(this.root, node)) {\n throw new Error(\n 'Cannot set currentNode to a node that is not contained by the root node.'\n );\n }\n\n const walkers: TreeWalker[] = [];\n let curNode: Node | null | undefined = node;\n let currentWalkerCurrentNode = node;\n\n this._currentNode = node;\n\n while (curNode && curNode !== this.root) {\n if (curNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n const shadowRoot = curNode as ShadowRoot;\n\n const walker = this._doc.createTreeWalker(\n shadowRoot,\n this.whatToShow,\n {acceptNode: this._acceptNode}\n );\n\n walkers.push(walker);\n\n walker.currentNode = currentWalkerCurrentNode;\n\n this._currentSetFor.add(walker);\n\n curNode = currentWalkerCurrentNode = shadowRoot.host;\n } else {\n curNode = curNode.parentNode;\n }\n }\n\n const walker = this._doc.createTreeWalker(\n this.root,\n this.whatToShow,\n {acceptNode: this._acceptNode}\n );\n\n walkers.push(walker);\n\n walker.currentNode = currentWalkerCurrentNode;\n\n this._currentSetFor.add(walker);\n\n this._walkerStack = walkers;\n }\n\n public get doc(): Document {\n return this._doc;\n }\n\n public firstChild(): Node | null {\n let currentNode = this.currentNode;\n let newNode = this.nextNode();\n if (!nodeContains(currentNode, newNode)) {\n this.currentNode = currentNode;\n return null;\n }\n if (newNode) {\n this.currentNode = newNode;\n }\n return newNode;\n }\n\n public lastChild(): Node | null {\n let walker = this._walkerStack[0];\n let newNode = walker.lastChild();\n if (newNode) {\n this.currentNode = newNode;\n }\n return newNode;\n }\n\n public nextNode(): Node | null {\n const nextNode = this._walkerStack[0].nextNode();\n\n if (nextNode) {\n const shadowRoot = (nextNode as Element).shadowRoot;\n\n if (shadowRoot) {\n let nodeResult: number | undefined;\n\n if (typeof this.filter === 'function') {\n nodeResult = this.filter(nextNode);\n } else if (this.filter?.acceptNode) {\n nodeResult = this.filter.acceptNode(nextNode);\n }\n\n if (nodeResult === NodeFilter.FILTER_ACCEPT) {\n this.currentNode = nextNode;\n return nextNode;\n }\n\n // _acceptNode should have added new walker for this shadow,\n // go in recursively.\n let newNode = this.nextNode();\n if (newNode) {\n this.currentNode = newNode;\n }\n return newNode;\n }\n\n if (nextNode) {\n this.currentNode = nextNode;\n }\n return nextNode;\n } else {\n if (this._walkerStack.length > 1) {\n this._walkerStack.shift();\n\n let newNode = this.nextNode();\n if (newNode) {\n this.currentNode = newNode;\n }\n return newNode;\n } else {\n return null;\n }\n }\n }\n\n public previousNode(): Node | null {\n const currentWalker = this._walkerStack[0];\n\n if (currentWalker.currentNode === currentWalker.root) {\n if (this._currentSetFor.has(currentWalker)) {\n this._currentSetFor.delete(currentWalker);\n\n if (this._walkerStack.length > 1) {\n this._walkerStack.shift();\n let newNode = this.previousNode();\n if (newNode) {\n this.currentNode = newNode;\n }\n return newNode;\n } else {\n return null;\n }\n }\n\n return null;\n }\n\n const previousNode = currentWalker.previousNode();\n\n if (previousNode) {\n const shadowRoot = (previousNode as Element).shadowRoot;\n\n if (shadowRoot) {\n let nodeResult: number | undefined;\n\n if (typeof this.filter === 'function') {\n nodeResult = this.filter(previousNode);\n } else if (this.filter?.acceptNode) {\n nodeResult = this.filter.acceptNode(previousNode);\n }\n\n if (nodeResult === NodeFilter.FILTER_ACCEPT) {\n if (previousNode) {\n this.currentNode = previousNode;\n }\n return previousNode;\n }\n\n // _acceptNode should have added new walker for this shadow,\n // go in recursively.\n let newNode = this.lastChild();\n if (newNode) {\n this.currentNode = newNode;\n }\n return newNode;\n }\n\n if (previousNode) {\n this.currentNode = previousNode;\n }\n return previousNode;\n } else {\n if (this._walkerStack.length > 1) {\n this._walkerStack.shift();\n\n let newNode = this.previousNode();\n if (newNode) {\n this.currentNode = newNode;\n }\n return newNode;\n } else {\n return null;\n }\n }\n }\n\n /**\n * @deprecated\n */\n public nextSibling(): Node | null {\n // if (__DEV__) {\n // throw new Error(\"Method not implemented.\");\n // }\n\n return null;\n }\n\n /**\n * @deprecated\n */\n public previousSibling(): Node | null {\n // if (__DEV__) {\n // throw new Error(\"Method not implemented.\");\n // }\n\n return null;\n }\n\n /**\n * @deprecated\n */\n public parentNode(): Node | null {\n // if (__DEV__) {\n // throw new Error(\"Method not implemented.\");\n // }\n\n return null;\n }\n}\n\n/**\n * ShadowDOM safe version of document.createTreeWalker.\n */\nexport function createShadowTreeWalker(\n doc: Document,\n root: Node,\n whatToShow?: number,\n filter?: NodeFilter | null\n) {\n if (shadowDOM()) {\n return new ShadowTreeWalker(doc, root, whatToShow, filter);\n }\n return doc.createTreeWalker(root, whatToShow, filter);\n}\n"],"names":[],"version":3,"file":"ShadowTreeWalker.main.js.map"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import {nodeContains as $d4ee10de306f2510$export$4282f70798064fe0} from "./DOMFunctions.mjs";
|
|
2
|
+
import {shadowDOM as $bJKXg$shadowDOM} from "@react-stately/flags";
|
|
3
|
+
|
|
4
|
+
// https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/ShadowTreeWalker.ts
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class $dfc540311bf7f109$export$63eb3ababa9c55c4 {
|
|
8
|
+
get currentNode() {
|
|
9
|
+
return this._currentNode;
|
|
10
|
+
}
|
|
11
|
+
set currentNode(node) {
|
|
12
|
+
if (!(0, $d4ee10de306f2510$export$4282f70798064fe0)(this.root, node)) throw new Error('Cannot set currentNode to a node that is not contained by the root node.');
|
|
13
|
+
const walkers = [];
|
|
14
|
+
let curNode = node;
|
|
15
|
+
let currentWalkerCurrentNode = node;
|
|
16
|
+
this._currentNode = node;
|
|
17
|
+
while(curNode && curNode !== this.root)if (curNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
18
|
+
const shadowRoot = curNode;
|
|
19
|
+
const walker = this._doc.createTreeWalker(shadowRoot, this.whatToShow, {
|
|
20
|
+
acceptNode: this._acceptNode
|
|
21
|
+
});
|
|
22
|
+
walkers.push(walker);
|
|
23
|
+
walker.currentNode = currentWalkerCurrentNode;
|
|
24
|
+
this._currentSetFor.add(walker);
|
|
25
|
+
curNode = currentWalkerCurrentNode = shadowRoot.host;
|
|
26
|
+
} else curNode = curNode.parentNode;
|
|
27
|
+
const walker = this._doc.createTreeWalker(this.root, this.whatToShow, {
|
|
28
|
+
acceptNode: this._acceptNode
|
|
29
|
+
});
|
|
30
|
+
walkers.push(walker);
|
|
31
|
+
walker.currentNode = currentWalkerCurrentNode;
|
|
32
|
+
this._currentSetFor.add(walker);
|
|
33
|
+
this._walkerStack = walkers;
|
|
34
|
+
}
|
|
35
|
+
get doc() {
|
|
36
|
+
return this._doc;
|
|
37
|
+
}
|
|
38
|
+
firstChild() {
|
|
39
|
+
let currentNode = this.currentNode;
|
|
40
|
+
let newNode = this.nextNode();
|
|
41
|
+
if (!(0, $d4ee10de306f2510$export$4282f70798064fe0)(currentNode, newNode)) {
|
|
42
|
+
this.currentNode = currentNode;
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (newNode) this.currentNode = newNode;
|
|
46
|
+
return newNode;
|
|
47
|
+
}
|
|
48
|
+
lastChild() {
|
|
49
|
+
let walker = this._walkerStack[0];
|
|
50
|
+
let newNode = walker.lastChild();
|
|
51
|
+
if (newNode) this.currentNode = newNode;
|
|
52
|
+
return newNode;
|
|
53
|
+
}
|
|
54
|
+
nextNode() {
|
|
55
|
+
const nextNode = this._walkerStack[0].nextNode();
|
|
56
|
+
if (nextNode) {
|
|
57
|
+
const shadowRoot = nextNode.shadowRoot;
|
|
58
|
+
if (shadowRoot) {
|
|
59
|
+
var _this_filter;
|
|
60
|
+
let nodeResult;
|
|
61
|
+
if (typeof this.filter === 'function') nodeResult = this.filter(nextNode);
|
|
62
|
+
else if ((_this_filter = this.filter) === null || _this_filter === void 0 ? void 0 : _this_filter.acceptNode) nodeResult = this.filter.acceptNode(nextNode);
|
|
63
|
+
if (nodeResult === NodeFilter.FILTER_ACCEPT) {
|
|
64
|
+
this.currentNode = nextNode;
|
|
65
|
+
return nextNode;
|
|
66
|
+
}
|
|
67
|
+
// _acceptNode should have added new walker for this shadow,
|
|
68
|
+
// go in recursively.
|
|
69
|
+
let newNode = this.nextNode();
|
|
70
|
+
if (newNode) this.currentNode = newNode;
|
|
71
|
+
return newNode;
|
|
72
|
+
}
|
|
73
|
+
if (nextNode) this.currentNode = nextNode;
|
|
74
|
+
return nextNode;
|
|
75
|
+
} else {
|
|
76
|
+
if (this._walkerStack.length > 1) {
|
|
77
|
+
this._walkerStack.shift();
|
|
78
|
+
let newNode = this.nextNode();
|
|
79
|
+
if (newNode) this.currentNode = newNode;
|
|
80
|
+
return newNode;
|
|
81
|
+
} else return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
previousNode() {
|
|
85
|
+
const currentWalker = this._walkerStack[0];
|
|
86
|
+
if (currentWalker.currentNode === currentWalker.root) {
|
|
87
|
+
if (this._currentSetFor.has(currentWalker)) {
|
|
88
|
+
this._currentSetFor.delete(currentWalker);
|
|
89
|
+
if (this._walkerStack.length > 1) {
|
|
90
|
+
this._walkerStack.shift();
|
|
91
|
+
let newNode = this.previousNode();
|
|
92
|
+
if (newNode) this.currentNode = newNode;
|
|
93
|
+
return newNode;
|
|
94
|
+
} else return null;
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const previousNode = currentWalker.previousNode();
|
|
99
|
+
if (previousNode) {
|
|
100
|
+
const shadowRoot = previousNode.shadowRoot;
|
|
101
|
+
if (shadowRoot) {
|
|
102
|
+
var _this_filter;
|
|
103
|
+
let nodeResult;
|
|
104
|
+
if (typeof this.filter === 'function') nodeResult = this.filter(previousNode);
|
|
105
|
+
else if ((_this_filter = this.filter) === null || _this_filter === void 0 ? void 0 : _this_filter.acceptNode) nodeResult = this.filter.acceptNode(previousNode);
|
|
106
|
+
if (nodeResult === NodeFilter.FILTER_ACCEPT) {
|
|
107
|
+
if (previousNode) this.currentNode = previousNode;
|
|
108
|
+
return previousNode;
|
|
109
|
+
}
|
|
110
|
+
// _acceptNode should have added new walker for this shadow,
|
|
111
|
+
// go in recursively.
|
|
112
|
+
let newNode = this.lastChild();
|
|
113
|
+
if (newNode) this.currentNode = newNode;
|
|
114
|
+
return newNode;
|
|
115
|
+
}
|
|
116
|
+
if (previousNode) this.currentNode = previousNode;
|
|
117
|
+
return previousNode;
|
|
118
|
+
} else {
|
|
119
|
+
if (this._walkerStack.length > 1) {
|
|
120
|
+
this._walkerStack.shift();
|
|
121
|
+
let newNode = this.previousNode();
|
|
122
|
+
if (newNode) this.currentNode = newNode;
|
|
123
|
+
return newNode;
|
|
124
|
+
} else return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated
|
|
129
|
+
*/ nextSibling() {
|
|
130
|
+
// if (__DEV__) {
|
|
131
|
+
// throw new Error("Method not implemented.");
|
|
132
|
+
// }
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @deprecated
|
|
137
|
+
*/ previousSibling() {
|
|
138
|
+
// if (__DEV__) {
|
|
139
|
+
// throw new Error("Method not implemented.");
|
|
140
|
+
// }
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @deprecated
|
|
145
|
+
*/ parentNode() {
|
|
146
|
+
// if (__DEV__) {
|
|
147
|
+
// throw new Error("Method not implemented.");
|
|
148
|
+
// }
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
constructor(doc, root, whatToShow, filter){
|
|
152
|
+
this._walkerStack = [];
|
|
153
|
+
this._currentSetFor = new Set();
|
|
154
|
+
this._acceptNode = (node)=>{
|
|
155
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
156
|
+
const shadowRoot = node.shadowRoot;
|
|
157
|
+
if (shadowRoot) {
|
|
158
|
+
const walker = this._doc.createTreeWalker(shadowRoot, this.whatToShow, {
|
|
159
|
+
acceptNode: this._acceptNode
|
|
160
|
+
});
|
|
161
|
+
this._walkerStack.unshift(walker);
|
|
162
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
163
|
+
} else {
|
|
164
|
+
var _this_filter;
|
|
165
|
+
if (typeof this.filter === 'function') return this.filter(node);
|
|
166
|
+
else if ((_this_filter = this.filter) === null || _this_filter === void 0 ? void 0 : _this_filter.acceptNode) return this.filter.acceptNode(node);
|
|
167
|
+
else if (this.filter === null) return NodeFilter.FILTER_ACCEPT;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return NodeFilter.FILTER_SKIP;
|
|
171
|
+
};
|
|
172
|
+
this._doc = doc;
|
|
173
|
+
this.root = root;
|
|
174
|
+
this.filter = filter !== null && filter !== void 0 ? filter : null;
|
|
175
|
+
this.whatToShow = whatToShow !== null && whatToShow !== void 0 ? whatToShow : NodeFilter.SHOW_ALL;
|
|
176
|
+
this._currentNode = root;
|
|
177
|
+
this._walkerStack.unshift(doc.createTreeWalker(root, whatToShow, this._acceptNode));
|
|
178
|
+
const shadowRoot = root.shadowRoot;
|
|
179
|
+
if (shadowRoot) {
|
|
180
|
+
const walker = this._doc.createTreeWalker(shadowRoot, this.whatToShow, {
|
|
181
|
+
acceptNode: this._acceptNode
|
|
182
|
+
});
|
|
183
|
+
this._walkerStack.unshift(walker);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function $dfc540311bf7f109$export$4d0f8be8b12a7ef6(doc, root, whatToShow, filter) {
|
|
188
|
+
if ((0, $bJKXg$shadowDOM)()) return new $dfc540311bf7f109$export$63eb3ababa9c55c4(doc, root, whatToShow, filter);
|
|
189
|
+
return doc.createTreeWalker(root, whatToShow, filter);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
export {$dfc540311bf7f109$export$63eb3ababa9c55c4 as ShadowTreeWalker, $dfc540311bf7f109$export$4d0f8be8b12a7ef6 as createShadowTreeWalker};
|
|
194
|
+
//# sourceMappingURL=ShadowTreeWalker.module.js.map
|