UNPKG

@appsurify-testmap/rrweb-utils

Version:

This package contains the shared utility functions used across rrweb packages. See the [guide](../../guide.md) for more info on rrweb.

21 lines (20 loc) 5.14 kB
(function (g, f) {if ("object" == typeof exports && "object" == typeof module) {module.exports = f();} else if ("function" == typeof define && define.amd) {define("rrwebUtils", [], f);} else if ("object" == typeof exports) {exports["rrwebUtils"] = f();} else {g["rrwebUtils"] = f();}}(typeof self !== 'undefined' ? self : typeof globalThis !== 'undefined' ? globalThis : this, () => {var exports = {};var module = { exports }; "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w={Node:["childNodes","parentNode","parentElement","textContent"],ShadowRoot:["host","styleSheets"],Element:["shadowRoot","querySelector","querySelectorAll"],MutationObserver:[]},N={Node:["contains","getRootNode"],ShadowRoot:["getSelection"],Element:[],MutationObserver:["constructor"]},d={},O=()=>!!globalThis.Zone;function h(t){if(d[t])return d[t];const e=globalThis[t],r=e.prototype,n=t in w?w[t]:void 0,o=!!(n&&n.every(i=>{var c,a;return!!((a=(c=Object.getOwnPropertyDescriptor(r,i))==null?void 0:c.get)!=null&&a.toString().includes("[native code]"))})),s=t in N?N[t]:void 0,u=!!(s&&s.every(i=>{var c;return typeof r[i]=="function"&&((c=r[i])==null?void 0:c.toString().includes("[native code]"))}));if(o&&u&&!O())return d[t]=e.prototype,e.prototype;try{const i=document.createElement("iframe");document.body.appendChild(i);const c=i.contentWindow;if(!c)return e.prototype;const a=c[t].prototype;return document.body.removeChild(i),a?d[t]=a:r}catch(i){return r}}const p={};function l(t,e,r){var n;const o=`${t}.${String(r)}`;if(p[o])return p[o].call(e);const s=h(t),u=(n=Object.getOwnPropertyDescriptor(s,r))==null?void 0:n.get;return u?(p[o]=u,u.call(e)):e[r]}const f={};function g(t,e,r){const n=`${t}.${String(r)}`;if(f[n])return f[n].bind(e);const s=h(t)[r];return typeof s!="function"?e[r]:(f[n]=s,s.bind(e))}function E(t){return l("Node",t,"childNodes")}function M(t){return l("Node",t,"parentNode")}function A(t){return l("Node",t,"parentElement")}function C(t){return l("Node",t,"textContent")}function _(t,e){return g("Node",t,"contains")(e)}function P(t){return g("Node",t,"getRootNode")()}function R(t){return!t||!("host"in t)?null:l("ShadowRoot",t,"host")}function x(t){return t.styleSheets}function V(t){return!t||!("shadowRoot"in t)?null:l("Element",t,"shadowRoot")}function q(t,e){return l("Element",t,"querySelector")(e)}function U(t,e){return l("Element",t,"querySelectorAll")(e)}function $(){return h("MutationObserver").constructor}function j(t,e,r){try{if(!(e in t))return()=>{};const n=t[e],o=r(n);return typeof o=="function"&&(o.prototype=o.prototype||{},Object.defineProperties(o,{__rrweb_original__:{enumerable:!1,value:n}})),t[e]=o,()=>{t[e]=n}}catch(n){return()=>{}}}function B(t){const e=t.tagName.toLowerCase(),r=t.id?`#${t.id}`:"",n=t.classList.length?"."+Array.from(t.classList).join("."):"";return`${e}${r}${n}`}function T(t,e){var r;let n=t.parentElement;for(;n;){const o=(r=e.getComputedStyle)==null?void 0:r.call(e,n);if(o&&(parseFloat(o.opacity)||0)<=0)return!1;n=n.parentElement}return!0}function H(t){var v;var e,r;const n=(v=(e=t.ownerDocument)==null?void 0:e.defaultView)!=null?v:window,o=t.getBoundingClientRect(),s=n.innerWidth||n.document.documentElement.clientWidth||0,u=n.innerHeight||n.document.documentElement.clientHeight||0,i=o.width>0&&o.height>0,c=i&&o.bottom>0&&o.right>0&&o.top<u&&o.left<s,a=(r=n.getComputedStyle)==null?void 0:r.call(n,t),y=!!a&&a.display!=="none"&&a.visibility!=="hidden"&&(parseFloat(a.opacity)||0)>0&&T(t,n),m=y&&c;let b=0;if(m){const W=Math.max(0,Math.min(o.right,s)-Math.max(o.left,0)),D=Math.max(0,Math.min(o.bottom,u)-Math.max(o.top,0)),L=W*D,S=o.width*o.height;b=S>0?L/S:0}return{isVisible:m,isCSSVisible:y,isViewportVisible:c,hasSize:i,ratio:b}}const Z={childNodes:E,parentNode:M,parentElement:A,textContent:C,contains:_,getRootNode:P,host:R,styleSheets:x,shadowRoot:V,querySelector:q,querySelectorAll:U,mutationObserver:$,patch:j,describeNode:B,getElementVisibility:H};exports.childNodes=E;exports.contains=_;exports.default=Z;exports.describeNode=B;exports.getElementVisibility=H;exports.getRootNode=P;exports.getUntaintedAccessor=l;exports.getUntaintedMethod=g;exports.getUntaintedPrototype=h;exports.host=R;exports.isAngularZonePresent=O;exports.mutationObserverCtor=$;exports.parentElement=A;exports.parentNode=M;exports.patch=j;exports.querySelector=q;exports.querySelectorAll=U;exports.shadowRoot=V;exports.styleSheets=x;exports.textContent=C; ;if (typeof module.exports == "object" && typeof exports == "object") { var __cp = (to, from, except, desc) => { if ((from && typeof from === "object") || typeof from === "function") { for (let key of Object.getOwnPropertyNames(from)) { if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except) Object.defineProperty(to, key, { get: () => from[key], enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable, }); } } return to; }; module.exports = __cp(module.exports, exports); } return module.exports; })) //# sourceMappingURL=rrweb-utils.umd.min.cjs.map