tftsr-devops_investigation/node_modules/webdriverio/build/scripts/isElementDisplayed.js

168 lines
5.3 KiB
JavaScript
Raw Normal View History

feat: initial implementation of TFTSR IT Triage & RCA application Implements Phases 1-8 of the TFTSR implementation plan. Rust backend (Tauri 2.x, src-tauri/): - Multi-provider AI: OpenAI-compatible, Anthropic, Gemini, Mistral, Ollama - PII detection engine: 11 regex patterns with overlap resolution - SQLCipher AES-256 encrypted database with 10 versioned migrations - 28 Tauri IPC commands for triage, analysis, document, and system ops - Ollama: hardware probe, model recommendations, pull/delete with events - RCA and blameless post-mortem Markdown document generators - PDF export via printpdf - Audit log: SHA-256 hash of every external data send - Integration stubs for Confluence, ServiceNow, Azure DevOps (v0.2) Frontend (React 18 + TypeScript + Vite, src/): - 9 pages: full triage workflow NewIssue→LogUpload→Triage→Resolution→RCA→Postmortem→History+Settings - 7 components: ChatWindow, TriageProgress, PiiDiffViewer, DocEditor, HardwareReport, ModelSelector, UI primitives - 3 Zustand stores: session, settings (persisted), history - Type-safe tauriCommands.ts matching Rust backend types exactly - 8 IT domain system prompts (Linux, Windows, Network, K8s, DB, Virt, HW, Obs) DevOps: - .woodpecker/test.yml: rustfmt, clippy, cargo test, tsc, vitest on every push - .woodpecker/release.yml: linux/amd64 + linux/arm64 builds, Gogs release upload Verified: - cargo check: zero errors - tsc --noEmit: zero errors - vitest run: 13/13 unit tests passing Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 03:36:25 +00:00
// src/scripts/isElementDisplayed.ts
function isElementDisplayed(element) {
function nodeIsElement(node) {
if (!node) {
return false;
}
switch (node.nodeType) {
case Node.ELEMENT_NODE:
case Node.DOCUMENT_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
return true;
default:
return false;
}
}
function parentElementForElement(element2) {
if (!element2) {
return null;
}
return enclosingNodeOrSelfMatchingPredicate(element2.parentNode, nodeIsElement);
}
function enclosingNodeOrSelfMatchingPredicate(targetNode, predicate) {
for (let node = targetNode; node && node !== targetNode.ownerDocument; node = node.parentNode) {
if (predicate(node)) {
return node;
}
}
return null;
}
function enclosingElementOrSelfMatchingPredicate(targetElement, predicate) {
for (let element2 = targetElement; element2 && element2 !== targetElement.ownerDocument; element2 = parentElementForElement(element2)) {
if (predicate(element2)) {
return element2;
}
}
return null;
}
function cascadedStylePropertyForElement(element2, property) {
if (!element2 || !property) {
return null;
}
if ("ShadowRoot" in window && element2 instanceof window.ShadowRoot) {
element2 = element2.host;
}
const computedStyle = window.getComputedStyle(element2);
const computedStyleProperty = computedStyle.getPropertyValue(property);
if (computedStyleProperty && computedStyleProperty !== "inherit") {
return computedStyleProperty;
}
const parentElement = parentElementForElement(element2);
return cascadedStylePropertyForElement(parentElement, property);
}
function elementHasBoundingBox(element2) {
const boundingBox = element2.getBoundingClientRect();
return boundingBox.width > 0 && boundingBox.height > 0;
}
function elementSubtreeHasNonZeroDimensions(element2) {
if (elementHasBoundingBox(element2)) {
return true;
}
const boundingBox = element2.getBoundingClientRect();
if (element2.tagName.toUpperCase() === "PATH" && boundingBox.width + boundingBox.height > 0) {
const strokeWidth = cascadedStylePropertyForElement(element2, "stroke-width");
return !!strokeWidth && parseInt(strokeWidth, 10) > 0;
}
const cascadedOverflow = cascadedStylePropertyForElement(element2, "overflow");
if (cascadedOverflow === "hidden") {
return false;
}
return [].some.call(element2.childNodes, function(childNode) {
if (childNode.nodeType === Node.TEXT_NODE) {
return true;
}
if (nodeIsElement(childNode)) {
return elementSubtreeHasNonZeroDimensions(childNode);
}
return false;
});
}
function elementOverflowsContainer(element2) {
const cascadedOverflow = cascadedStylePropertyForElement(element2, "overflow");
if (cascadedOverflow !== "hidden") {
return false;
}
return true;
}
function isElementSubtreeHiddenByOverflow(element2) {
if (!element2) {
return false;
}
if (!elementOverflowsContainer(element2)) {
return false;
}
if (!element2.childNodes.length) {
return false;
}
return [].every.call(element2.childNodes, function(childNode) {
if (childNode.nodeType === Node.TEXT_NODE) {
return false;
}
if (!nodeIsElement(childNode)) {
return true;
}
if (!elementSubtreeHasNonZeroDimensions(childNode)) {
return true;
}
return isElementSubtreeHiddenByOverflow(childNode);
});
}
function isElementInsideShadowRoot(element2) {
if (!element2) {
return false;
}
if (element2.parentNode && element2.parentNode.host) {
return true;
}
return isElementInsideShadowRoot(element2.parentNode);
}
if (!isElementInsideShadowRoot(element) && (typeof document.contains === "function" ? !document.contains(element) : !document.body.contains(element))) {
return false;
}
switch (element.tagName.toUpperCase()) {
case "BODY":
return true;
case "SCRIPT":
case "NOSCRIPT":
return false;
case "OPTGROUP":
case "OPTION": {
const enclosingSelectElement = enclosingNodeOrSelfMatchingPredicate(element, function(e) {
return e.tagName.toUpperCase() === "SELECT";
});
return isElementDisplayed(enclosingSelectElement);
}
case "INPUT":
if (element.type === "hidden") {
return false;
}
break;
case "MAP":
break;
default:
break;
}
if (cascadedStylePropertyForElement(element, "visibility") !== "visible") {
return false;
}
const hasAncestorWithZeroOpacity = !!enclosingElementOrSelfMatchingPredicate(element, function(e) {
return Number(cascadedStylePropertyForElement(e, "opacity")) === 0;
});
const hasAncestorWithDisplayNone = !!enclosingElementOrSelfMatchingPredicate(element, function(e) {
return cascadedStylePropertyForElement(e, "display") === "none";
});
if (hasAncestorWithZeroOpacity || hasAncestorWithDisplayNone) {
return false;
}
if (!elementSubtreeHasNonZeroDimensions(element)) {
return false;
}
if (isElementSubtreeHiddenByOverflow(element) && !elementHasBoundingBox(element)) {
return false;
}
return true;
}
export {
isElementDisplayed as default
};