UNPKG

js-use-core

Version:

JavaScript Comprehensive tool library, including full screen, copy and paste functions

2 lines (1 loc) 20.5 kB
"use strict";function e(e){return!(!e||"object"!=typeof e||e.nodeType!==Node.ELEMENT_NODE)}function t(t){if(!t)return null;if(e(t))return t;if("string"==typeof t)try{return document.querySelector(t)}catch(e){return null}return null}const r=["","webkit","moz","ms","o"];function n(e){if(e in document.documentElement.style||e in window||e in document)return{supported:!0};for(const t of r.slice(1)){const r=`${t}${e.charAt(0).toUpperCase()}${e.slice(1)}`;if(r in document.documentElement.style||r in window||r in document)return{supported:!0,prefixedName:r,prefix:t}}return{supported:!1}}function s(e){const t=n(e);return t.supported?t.prefixedName||e:null}const o=new class{constructor(){this.listeners=new WeakMap}add(e,t,r,n){e.addEventListener(t,r,n),this.listeners.has(e)||this.listeners.set(e,new Map);const s=this.listeners.get(e);return s.has(t)||s.set(t,new Set),s.get(t).add(r),()=>this.remove(e,t,r,n)}remove(e,t,r,n){e.removeEventListener(t,r,n);const s=this.listeners.get(e);if(s){const e=s.get(t);e&&(e.delete(r),0===e.size&&s.delete(t))}}removeAll(e){const t=this.listeners.get(e);if(t){for(const[r,n]of t)for(const t of n)e.removeEventListener(r,t);this.listeners.delete(e)}}};function i(e,r,n,s){const i=(e instanceof Element?e:t(e))||e;if(!i)throw new Error("Invalid event target");return o.add(i,r,n,s)}function c(e,t,r){return new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0,...r})}const a=new class{constructor(){this.operations=[],this.rafId=null}add(e){this.operations.push(e),this.schedule()}schedule(){null===this.rafId&&(this.rafId=requestAnimationFrame(()=>{this.flush()}))}flush(){const e=this.operations.splice(0);this.rafId=null;for(const t of e)try{t()}catch(e){}}flushSync(){null!==this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.flush()}};function u(){return document.createDocumentFragment()}class Cache{constructor(e){this.cache=new Map,this.config={maxSize:e?.maxSize??100,defaultTTL:e?.defaultTTL??3e5,enableLRU:e?.enableLRU??!0,cleanupInterval:e?.cleanupInterval??6e4},this.startCleanup()}set(e,t,r){const n=Date.now(),s={value:t,expireAt:n+(r??this.config.defaultTTL),createdAt:n,accessCount:0,lastAccessed:n};this.cache.size>=this.config.maxSize&&!this.cache.has(e)&&this.evictLRU(),this.cache.set(e,s)}get(e){const t=this.cache.get(e);if(!t)return;const r=Date.now();if(!(r>t.expireAt))return t.accessCount++,t.lastAccessed=r,t.value;this.cache.delete(e)}has(e){const t=this.cache.get(e);return!!t&&(!(Date.now()>t.expireAt)||(this.cache.delete(e),!1))}delete(e){return this.cache.delete(e)}clear(){this.cache.clear()}size(){return this.cache.size}keys(){return Array.from(this.cache.keys())}getInfo(e){const t=this.cache.get(e);if(t){if(!(Date.now()>t.expireAt))return{...t};this.cache.delete(e)}}touch(e,t){const r=this.cache.get(e);if(!r)return!1;const n=Date.now();if(n>r.expireAt)return this.cache.delete(e),!1;const s=t??this.config.defaultTTL;return r.expireAt=n+s,r.lastAccessed=n,!0}async getOrSet(e,t,r){const n=this.get(e);if(void 0!==n)return n;const s=await t();return this.set(e,s,r),s}mset(e,t){for(const[r,n]of e)this.set(r,n,t)}mget(e){return e.map(e=>this.get(e))}mdel(e){let t=0;for(const r of e)this.delete(r)&&t++;return t}getStats(){let e=0,t=0;const r=Date.now();for(const[n,s]of this.cache.entries())e+=s.accessCount,r>s.expireAt&&t++;return{size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?(e-t)/e:0,totalAccess:e,expiredCount:t}}cleanup(){const e=Date.now();let t=0;for(const[r,n]of this.cache.entries())e>n.expireAt&&(this.cache.delete(r),t++);return t}evictLRU(){if(!this.config.enableLRU||0===this.cache.size)return;let e=null,t=1/0;for(const[r,n]of this.cache.entries())n.lastAccessed<t&&(t=n.lastAccessed,e=r);e&&this.cache.delete(e)}startCleanup(){this.cleanupTimer&&clearInterval(this.cleanupTimer),this.cleanupTimer=setInterval(()=>{this.cleanup()},this.config.cleanupInterval)}stopCleanup(){this.cleanupTimer&&(clearInterval(this.cleanupTimer),this.cleanupTimer=void 0)}updateConfig(e){if(this.config={...this.config,...e},void 0!==e.cleanupInterval&&this.startCleanup(),void 0!==e.maxSize&&this.cache.size>e.maxSize)for(;this.cache.size>e.maxSize;)this.evictLRU()}destroy(){this.stopCleanup(),this.clear()}}var l,d,h,R;!function(e){e.USER_ERROR="USER_ERROR",e.SYSTEM_ERROR="SYSTEM_ERROR",e.NETWORK_ERROR="NETWORK_ERROR",e.PERMISSION_ERROR="PERMISSION_ERROR",e.CONFIG_ERROR="CONFIG_ERROR",e.TIMEOUT_ERROR="TIMEOUT_ERROR",e.VALIDATION_ERROR="VALIDATION_ERROR",e.INTERNAL_ERROR="INTERNAL_ERROR",e.UNKNOWN_ERROR="UNKNOWN_ERROR"}(l||(l={})),function(e){e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR"}(d||(d={}));class Logger{constructor(e="Core",t){this.level=d.INFO,this.logs=[],this.maxLogs=1e3,this.enableConsole=!0,this.module=e,t&&(this.level=t.level??d.INFO,this.maxLogs=t.maxLogs??1e3,this.enableConsole=t.enableConsole??!0)}setLevel(e){this.level=e}getLevel(){return this.level}debug(e,t){this.log(d.DEBUG,e,t)}info(e,t){this.log(d.INFO,e,t)}warn(e,t){this.log(d.WARN,e,t)}error(e,t){this.log(d.ERROR,e,t)}log(e,t,r){if(e<this.level)return;const n={level:e,message:t,timestamp:Date.now(),module:this.module,data:r};this.logs.push(n),this.logs.length>this.maxLogs&&this.logs.shift(),this.enableConsole&&this.outputToConsole(n)}outputToConsole(e){new Date(e.timestamp).toISOString(),d[e.level],e.module,e.message,void 0!==e.data&&e.data;switch(e.level){case d.DEBUG:case d.INFO:case d.WARN:case d.ERROR:}}getLogs(){return[...this.logs]}getLogsByLevel(e){return this.logs.filter(t=>t.level===e)}getLogsByTimeRange(e,t){return this.logs.filter(r=>r.timestamp>=e&&r.timestamp<=t)}clear(){this.logs=[]}setMaxLogs(e){if(e<0)throw new Error("Max logs must be non-negative");this.maxLogs=e,this.logs.length>e&&(this.logs=this.logs.slice(-e))}setConsoleOutput(e){this.enableConsole=e}exportLogs(){return JSON.stringify(this.logs,null,2)}importLogs(e){try{const t=JSON.parse(e);Array.isArray(t)&&(this.logs=t.filter(e=>e&&"number"==typeof e.level&&"string"==typeof e.message&&"number"==typeof e.timestamp))}catch(e){this.error("Failed to import logs",e)}}createChild(e){return new Logger(`${this.module}.${e}`,{level:this.level,maxLogs:this.maxLogs,enableConsole:this.enableConsole})}}!function(e){e.USER_ERROR="USER_ERROR",e.SYSTEM_ERROR="SYSTEM_ERROR",e.NETWORK_ERROR="NETWORK_ERROR",e.PERMISSION_ERROR="PERMISSION_ERROR",e.CONFIG_ERROR="CONFIG_ERROR",e.VALIDATION_ERROR="VALIDATION_ERROR",e.TIMEOUT_ERROR="TIMEOUT_ERROR",e.UNSUPPORTED_ERROR="UNSUPPORTED_ERROR",e.INTERNAL_ERROR="INTERNAL_ERROR",e.EXTERNAL_ERROR="EXTERNAL_ERROR",e.UNKNOWN_ERROR="UNKNOWN_ERROR"}(h||(h={})),function(e){e.LOW="low",e.MEDIUM="medium",e.HIGH="high",e.CRITICAL="critical"}(R||(R={}));class p extends Error{constructor(e,t,r){super(t),this.name="CustomError",this.type=e,this.code=r?.code,this.context=r?.context,this.recoverable=r?.recoverable??!1,r?.cause&&(this.cause=r.cause),Error.captureStackTrace&&Error.captureStackTrace(this,p)}}class ErrorHandler{constructor(e){this.errorSolutions=new Map,this.logger=e||new Logger("ErrorHandler"),this.initializeErrorSolutions()}handleError(e,t){const r=this.classifyError(e),n={module:"Unknown",method:"Unknown",timestamp:Date.now(),userAgent:"undefined"!=typeof navigator?navigator.userAgent:"Node.js",...t},s={type:r,severity:this.getErrorSeverity(r),message:e.message,userMessage:this.getUserFriendlyMessage(e,r),originalError:e,context:n,code:this.getErrorCode(e)||this.generateErrorCode(r),recoverable:this.isRecoverableError(e),solutions:this.getErrorSolutions(e),id:this.generateErrorId(),processedAt:Date.now(),relatedErrors:[]};return this.logger.error(`[${r}] ${s.message}`,{error:e.message,stack:e.stack,context:n,recoverable:s.recoverable}),s}createError(e,t,r){const n={module:"Unknown",method:"Unknown",timestamp:Date.now(),userAgent:"undefined"!=typeof navigator?navigator.userAgent:"Node.js",...r?.context};return new p(e,t,{code:r?.code,context:n,recoverable:r?.recoverable,cause:r?.cause})}isRecoverableError(e){if(e instanceof p)return e.recoverable;switch(this.classifyError(e)){case h.NETWORK_ERROR:case h.TIMEOUT_ERROR:return!0;case h.PERMISSION_ERROR:case h.SYSTEM_ERROR:return!1;case h.USER_ERROR:case h.CONFIG_ERROR:return!0;default:return!1}}getErrorSolution(e){const t=this.getErrorCode(e);if(t&&this.errorSolutions.has(t))return this.errorSolutions.get(t);const r=this.classifyError(e);return this.getDefaultSolution(r)}getErrorSolutions(e){const t=this.getErrorSolution(e);return t?[{description:t,steps:[t],automatic:!1,priority:1}]:[]}getErrorSeverity(e){switch(e){case h.USER_ERROR:case h.CONFIG_ERROR:return R.LOW;case h.NETWORK_ERROR:case h.TIMEOUT_ERROR:return R.MEDIUM;case h.PERMISSION_ERROR:case h.VALIDATION_ERROR:return R.HIGH;case h.SYSTEM_ERROR:case h.INTERNAL_ERROR:return R.CRITICAL;default:return R.MEDIUM}}generateErrorCode(e){return`${e}_${Date.now().toString(36)}_${Math.random().toString(36).substr(2,5)}`.toUpperCase()}generateErrorId(){return`error_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}addErrorSolution(e,t){this.errorSolutions.set(e,t)}addErrorSolutions(e){for(const[t,r]of Object.entries(e))this.errorSolutions.set(t,r)}classifyError(e){if(e instanceof p)return e.type;const t=(e.message||"").toLowerCase(),r=(e.name||"").toLowerCase();return t.includes("network")||t.includes("fetch")||t.includes("xhr")||r.includes("networkerror")?h.NETWORK_ERROR:t.includes("timeout")||t.includes("timed out")||r.includes("timeouterror")?h.TIMEOUT_ERROR:t.includes("permission")||t.includes("denied")||t.includes("unauthorized")||t.includes("forbidden")||r.includes("notallowederror")?h.PERMISSION_ERROR:t.includes("not supported")||t.includes("not available")||t.includes("not implemented")||r.includes("notsupportederror")?h.SYSTEM_ERROR:t.includes("invalid")||t.includes("configuration")||t.includes("config")||r.includes("configerror")?h.CONFIG_ERROR:e instanceof TypeError||e instanceof RangeError||t.includes("invalid argument")||t.includes("invalid parameter")?h.USER_ERROR:h.UNKNOWN_ERROR}getUserFriendlyMessage(e,t){switch(t){case h.NETWORK_ERROR:return"网络连接失败,请检查网络连接后重试";case h.TIMEOUT_ERROR:return"操作超时,请稍后重试";case h.PERMISSION_ERROR:return"权限不足,请检查浏览器权限设置";case h.SYSTEM_ERROR:return"当前浏览器不支持此功能,请使用其他浏览器或升级浏览器版本";case h.CONFIG_ERROR:return"配置参数错误,请检查配置";case h.USER_ERROR:return"输入参数错误,请检查输入参数";default:return e.message||"发生未知错误"}}getErrorCode(e){if(e instanceof p)return e.code;const t=e;return t.code||t.errno||void 0}getDefaultSolution(e){switch(e){case h.NETWORK_ERROR:return"请检查网络连接,确保网络正常后重试";case h.TIMEOUT_ERROR:return"请稍后重试,或增加超时时间设置";case h.PERMISSION_ERROR:return"请在浏览器设置中允许相关权限,或使用HTTPS协议";case h.SYSTEM_ERROR:return"请使用支持此功能的现代浏览器,或升级浏览器版本";case h.CONFIG_ERROR:return"请检查配置参数是否正确,参考文档进行配置";case h.USER_ERROR:return"请检查输入参数的类型和格式是否正确";default:return null}}initializeErrorSolutions(){this.errorSolutions.set("ENOTFOUND","域名解析失败,请检查网络连接"),this.errorSolutions.set("ECONNREFUSED","连接被拒绝,请检查服务器状态"),this.errorSolutions.set("ETIMEDOUT","连接超时,请检查网络连接或稍后重试"),this.errorSolutions.set("CERT_UNTRUSTED","SSL证书不受信任,请检查证书配置"),this.errorSolutions.set("MIXED_CONTENT","混合内容错误,请使用HTTPS协议")}}class m{constructor(e={}){this.VENDOR_PREFIXES=["","webkit","moz","ms","o"],this.CSS_PREFIXES=["","-webkit-","-moz-","-ms-","-o-"],this.browserInfo=null,this.config={enableCache:!0,cacheTimeout:3e5,debug:!1,customPrefixes:[],...e},this.cache=new Cache({maxSize:200,defaultTTL:this.config.cacheTimeout,enableLRU:!0}),this.logger=new Logger("BrowserAdapter",{level:this.config.debug?0:2,enableConsole:this.config.debug}),this.errorHandler=new ErrorHandler}isSupported(e){return this.detectFeature(e).supported}getPrefixedProperty(e){const t=this.detectFeature(e,"property");return t.supported?t.prefixedName||e:null}getPrefixedMethod(e,t=window){const r=this.detectFeature(e,"method",t);if(!r.supported)return null;return t[r.prefixedName||e]||null}getPrefixedCSSProperty(e){const t=this.detectFeature(e,"css");return t.supported?t.prefixedName||e:null}detectFeature(e,t="property",r=null){const n=`${e}_${t}_${r?"custom":"default"}`;if(this.config.enableCache){const t=this.cache.get(n);if(t)return this.logger.debug(`Feature detection cache hit: ${e}`),t}let s;try{switch(t){case"property":default:s=this.detectProperty(e);break;case"method":s=this.detectMethod(e,null===r?null:r||window);break;case"css":s=this.detectCSSProperty(e);break;case"api":s=this.detectAPI(e);break;case"custom":s=this.detectCustomFeature(e,r)}return s.timestamp=Date.now(),this.config.enableCache&&this.cache.set(n,s),this.logger.debug(`Feature detection result for ${e}:`,s),s}catch(n){const s={module:"BrowserAdapter",method:"detectFeature",input:{feature:e,method:t,target:r},timestamp:Date.now()};return this.errorHandler.handleError(n,s),{supported:!1,method:t,timestamp:Date.now()}}}detectProperty(e){const t=[document.documentElement.style,window,document,navigator];for(const r of t)if(e in r)return{supported:!0,method:"property",timestamp:Date.now()};const r=[...this.VENDOR_PREFIXES.slice(1),...this.config.customPrefixes];for(const n of r){const r=this.getPrefixedName(e,n);for(const e of t)if(r in e)return{supported:!0,prefixedName:r,prefix:n,method:"property",timestamp:Date.now()}}return{supported:!1,method:"property",timestamp:Date.now()}}detectMethod(e,t){if(!t||"object"!=typeof t)return{supported:!1,method:"method",timestamp:Date.now()};if("function"==typeof t[e])return{supported:!0,method:"method",timestamp:Date.now()};const r=[...this.VENDOR_PREFIXES.slice(1),...this.config.customPrefixes];for(const n of r){const r=this.getPrefixedName(e,n);if("function"==typeof t[r])return{supported:!0,prefixedName:r,prefix:n,method:"method",timestamp:Date.now()}}return{supported:!1,method:"method",timestamp:Date.now()}}detectCSSProperty(e){const t=document.createElement("div").style;if(e in t)return{supported:!0,method:"css",timestamp:Date.now()};for(const r of this.CSS_PREFIXES.slice(1)){const n=`${r}${e}`;if(n in t)return{supported:!0,prefixedName:n,prefix:r.replace(/-/g,""),method:"css",timestamp:Date.now()}}try{if(t.setProperty(e,"initial"),t.getPropertyValue(e))return{supported:!0,method:"css",timestamp:Date.now()}}catch{}return{supported:!1,method:"css",timestamp:Date.now()}}detectAPI(e){const t=[e,`window.${e}`,`navigator.${e}`,`document.${e}`];for(const e of t)try{if(void 0!==this.getNestedProperty(window,e))return{supported:!0,method:"api",timestamp:Date.now()}}catch{continue}return{supported:!1,method:"api",timestamp:Date.now()}}detectCustomFeature(e,t){try{let e=!1;return"function"==typeof t?e=t():"boolean"==typeof t?e=t:t&&"function"==typeof t.test&&(e=t.test()),{supported:e,method:"custom",timestamp:Date.now()}}catch{return{supported:!1,method:"custom",timestamp:Date.now()}}}getPrefixedName(e,t){return t?`${t}${e.charAt(0).toUpperCase()}${e.slice(1)}`:e}getNestedProperty(e,t){return t.split(".").reduce((e,t)=>e&&void 0!==e[t]?e[t]:void 0,e)}getBrowserInfo(){if(this.browserInfo)return this.browserInfo;const e=navigator.userAgent,t={name:"Unknown",version:"0.0.0",engine:"Unknown",mobile:!1,os:"Unknown"};if(e.includes("Chrome")){t.name="Chrome",t.engine="Blink";const r=e.match(/Chrome\/(\d+\.\d+)/);r&&(t.version=r[1])}else if(e.includes("Firefox")){t.name="Firefox",t.engine="Gecko";const r=e.match(/Firefox\/(\d+\.\d+)/);r&&(t.version=r[1])}else if(e.includes("Safari")&&!e.includes("Chrome")){t.name="Safari",t.engine="WebKit";const r=e.match(/Version\/(\d+\.\d+)/);r&&(t.version=r[1])}else if(e.includes("Edge")){t.name="Edge",t.engine="Blink";const r=e.match(/Edge\/(\d+\.\d+)/);r&&(t.version=r[1])}return t.mobile=/Mobile|Android|iPhone|iPad/.test(e),e.includes("Windows")?t.os="Windows":e.includes("Mac")?t.os="macOS":e.includes("Linux")?t.os="Linux":e.includes("Android")?t.os="Android":(e.includes("iPhone")||e.includes("iPad"))&&(t.os="iOS"),this.browserInfo=t,t}addEventListenerCompat(e,t,r,n){if(e.addEventListener)return e.addEventListener(t,r,n),()=>e.removeEventListener(t,r,n);const s=e;if(s.attachEvent){const n=t=>{!t.target&&t.srcElement&&Object.defineProperty(t,"target",{value:t.srcElement,writable:!1,enumerable:!0,configurable:!0}),t.preventDefault=t.preventDefault||(()=>{t.returnValue=!1}),t.stopPropagation=t.stopPropagation||(()=>{t.cancelBubble=!0}),r.call(e,t)};return s.attachEvent(`on${t}`,n),()=>s.detachEvent(`on${t}`,n)}const o=`on${t}`,i=e[o];return e[o]=t=>{i&&i.call(e,t),r.call(e,t)},()=>{e[o]=i}}clearCache(){this.cache.clear(),this.browserInfo=null,this.logger.info("Browser adapter cache cleared")}getCacheStats(){const e=this.cache.getStats();return{size:this.cache.size(),hitRate:e.hitRate,maxSize:e.maxSize}}destroy(){this.clearCache(),this.logger.info("Browser adapter destroyed")}}let f=null;exports.addEventListener=i,exports.appendElements=function(e,r,n={}){const s=t(e);if(!s)throw new Error("Invalid container element");const{useFragment:o=!0}=n;if(o&&r.length>1){const e=u();r.forEach(t=>{if("string"==typeof t){const r=document.createElement("div");for(r.innerHTML=t;r.firstChild;)e.appendChild(r.firstChild)}else e.appendChild(t)}),s.appendChild(e)}else r.forEach(e=>{"string"==typeof e?s.insertAdjacentHTML("beforeend",e):s.appendChild(e)})},exports.batchDOMOperations=function(e){e.forEach(e=>a.add(e))},exports.checkBrowserSupport=n,exports.createCustomEvent=c,exports.createDocumentFragment=u,exports.delegate=function(e,r,n,s,o){const c=t(e);if(!c)throw new Error("Invalid container for event delegation");return i(c,n,e=>{const t=e.target.closest(r);t&&c.contains(t)&&s(e,t)},o)},exports.dispatchCustomEvent=function(e,r,n,s){const o=t(e);if(!o)throw new Error("Invalid event target for dispatch");const i=c(r,n,s);return o.dispatchEvent(i)},exports.flushBatchedOperations=function(){a.flushSync()},exports.getBrowserAdapter=function(e){return f||(f=new m(e)),f},exports.getElement=t,exports.getElements=function(e){try{return Array.from(document.querySelectorAll(e))}catch(e){return[]}},exports.getPrefixedCSSProperty=s,exports.getPrefixedProperty=function(e){return s(e)},exports.isDocument=function(e){return e&&e.nodeType===Node.DOCUMENT_NODE},exports.isElement=e,exports.isElementInViewport=function(e,r=0){const n=t(e);if(!n)return!1;const s=n.getBoundingClientRect(),o=window.innerHeight||document.documentElement.clientHeight,i=window.innerWidth||document.documentElement.clientWidth;return s.top>=-r&&s.left>=-r&&s.bottom<=o+r&&s.right<=i+r},exports.isHTMLElement=function(t){return e(t)&&t instanceof HTMLElement},exports.isSupported=function(e){return n(e).supported},exports.measureElement=function(e){const r=t(e);return r?r.getBoundingClientRect():null},exports.ready=function(e){"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()},exports.removeAllEventListeners=function(e){const r=(e instanceof Element?e:t(e))||e;r&&o.removeAll(r)},exports.removeEventListener=function(e,r,n,s){const i=(e instanceof Element?e:t(e))||e;if(!i)throw new Error("Invalid event target");o.remove(i,r,n,s)},exports.setAttributes=function(e,r){const n=t(e);if(!n)throw new Error("Invalid target element for attribute setting");a.add(()=>{Object.entries(r).forEach(([e,t])=>{n.setAttribute(e,t)})})},exports.setStyles=function(e,r){const n=t(e);if(!n)throw new Error("Invalid target element for style setting");a.add(()=>{Object.assign(n.style,r)})},exports.supportsCSSFeature=function(e,t){const r=document.createElement("div"),n=s(e);if(!n)return!1;try{return r.style[n]=t||"initial",""!==r.style[n]}catch{return!1}},exports.supportsHTML5Feature=function(e){return e in document.createElement("div")},exports.waitForElement=function(e,r=5e3){return new Promise((n,s)=>{const o=t(e);if(o)return void n(o);const i=new MutationObserver(()=>{const r=t(e);r&&(i.disconnect(),clearTimeout(c),n(r))}),c=setTimeout(()=>{i.disconnect(),s(new Error(`Element ${e} not found within ${r}ms`))},r);i.observe(document.body,{childList:!0,subtree:!0})})};