window.interop = { getElement: function (elementRef) { // Function to get the CSS selector for the given element reference return new Promise((resolve, reject) => { try { const selector = document.querySelector(elementRef); if (selector) { resolve(true); } else { reject(false); } } catch (error) { reject(error); } }); }, isEleExist: function (elementRef) { // Function to get the CSS selector for the given element reference const selector = document.querySelector(elementRef); if (selector) { return true; } else { return false; } }, getBoundry: function (elementRef) { const rect = elementRef?.getBoundingClientRect(); return rect; }, inner: function (arg) { if (arg == "innerWidth") { return window.innerWidth ?? 992; } if (arg == "innerHeight") { return window.innerHeight ?? 992; } return 0 }, MenuNavElement: function (elementRef) { // Function to get the width of the given element reference return new Promise((resolve, reject) => { try { const element = document.querySelector(elementRef); if (element) { const scrollWidth = element.scrollWidth; // Get the scrollWidth of the element const marginInlineStart = Math.ceil( Number( window.getComputedStyle(element).marginInlineStart.split("px")[0] ) ); // Get the scrollWidth of the element resolve({ scrollWidth, marginInlineStart }); // Return both element and width } else { reject("Element not found"); } } catch (error) { reject(error); } }); }, MenuNavmarginInlineStart: function (selector, value) { // Function to get the width of the given element reference return new Promise((resolve, reject) => { try { const element = document.querySelector(selector); if (element) { element.style.marginInlineStart = value; resolve(element); // Return both element and width } else { reject("Element not found"); } } catch (error) { reject(error); } }); }, mainSidebarOffset: function (elementRef) { // Function to get the width of the given element reference return new Promise((resolve, reject) => { try { const element = document.querySelector(elementRef); if (element) { const mainSidebarOffset = element.offsetWidth; // Get the scrollWidth of the element resolve(mainSidebarOffset); // Return both element and width } else { reject("Element not found"); } } catch (error) { reject(error); } }); }, addClass: function (elementRef, className) { const element = document.querySelector(elementRef); if (element) { element.classList.add(className); } }, removeClass: function (elementRef, className) { const element = document.querySelector(elementRef); if (element) { element.classList.remove(className); } }, addClassToHtml: (className) => { document.documentElement.classList.add(className); }, setclearCssVariables: function () { document.documentElement.style = ""; }, setCssVariable: function (variableName, value) { document.documentElement.style.setProperty(variableName, value); }, removeCssVariable: function (variableName, value) { document.documentElement.style.removeProperty(variableName, value); }, setCustomCssVariable: function (element, variableName, value) { let ele = document.querySelector(element); if (ele) { ele.style.setProperty(variableName, value); } }, removeClassFromHtml: (className) => { document.documentElement.classList.remove(className); }, getAttributeToHtml: (attributeName) => { return document.documentElement.getAttribute(attributeName); }, addAttributeToHtml: (attributeName, attributeValue) => { document.documentElement.setAttribute(attributeName, attributeValue); }, removeAttributeFromHtml: (attributeName) => { document.documentElement.removeAttribute(attributeName); }, getAttribute: function (elementRef, attributeName) { return new Promise((resolve, reject) => { try { const selector = document.querySelector(elementRef); if (selector) { resolve(selector.getAttribute(attributeName)); } else { reject("Element not found"); } } catch (error) { reject(error); } }); }, setAttribute: function (elementRef, attributeName, attributeValue) { return new Promise((resolve, reject) => { try { const selector = document.querySelector(elementRef); if (selector) { resolve(selector.setAttribute(attributeName, attributeValue)); } else { reject("Element not found"); } } catch (error) { reject(error); } }); }, setLocalStorageItem: function (key, value) { localStorage.setItem(key, value); }, removeLocalStorageItem: function (key) { localStorage.removeItem(key); }, getAllLocalStorageItem: function () { return localStorage; }, getLocalStorageItem: function (key) { return localStorage.getItem(key); }, clearAllLocalStorage: function () { localStorage.clear(); }, directionChange: function (dataId) { let element = document.querySelector(`[data-id="${dataId}"]`); let html = document.documentElement; if (element) { const listItem = element.closest("li"); if (listItem) { // Find the first sibling