diff --git a/build/index.js b/build/index.js index 05756d3..c4e1537 100644 --- a/build/index.js +++ b/build/index.js @@ -1 +1 @@ -import e from"array-from";var t=function(){return t=Object.assign||function(e){for(var t,n=1,i=arguments.length;i>n;n++)for(var r in t=arguments[n])({}).hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},t.apply(this,arguments)};function n(e,t,n){if(n||2===arguments.length)for(var i,r=0,o=t.length;o>r;r++)!i&&r in t||(i||(i=[].slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||[].slice.call(t))}var i=function(e){try{return e()}catch(e){return}},r=function(e){return"number"===f(e)},o=function(e){return"object"===f(e)&&!function(e){return s(["undefined","null"],f(e))}(e)},a=function(e){return Array.isArray(e)&&"array"===f(e)},u=function(e,t){var n=-1;if(a(e))for(var i=0;i=0},c=e,l=function(e){return a(e)?0===e.length:o(e)?0===function(e){return o(e)?Object.keys(e):[]}(e).length:!e},d=function(e){if(a(e)){for(var t=0,n=[],i=0,r=e;it;if(n>t)return!0;for(var i=0;i0?t:void 0):""},F=/[^/]*.(bmp|jpg|jpeg|png|gif|svg|psd|webp|apng)/gi,M=function(e,t){switch(t){case"a":return function(e){if(I(e,"href")){var t=T(e,"href");if(t&&0!==t.indexOf("javascript"))return t.slice(0,320)}return""}(e);case"img":return function(e){var t=e.src;if(t&&-1===t.indexOf("data:image")){var n=t.match(F),i=l(n)?"":n[0];if(i.indexOf("%")>-1){var r=function(e,t){var n=-1;if(a(e))for(var i=0;i0&&t.every((function(e){return function(e){if("svg"===e.tagName)return!0;var t=D(e);if(l(t))return!0;var n=z(e);return!(!l(t)&&!n)}(e)}))}(e)&&!A(e)?B(V(e)):A(e)?B(Y(e)):""},U=function(e,t){for(var n=e.parentElement;n&&!H(n);){if(t(n))return n;n=n.parentElement}},V=function(e){var t=D(e);return d(t.map((function(e){var t=W(e);if(z(e)&&t)return t}))).join(" ")},Y=function(e){var t;return D(e).some((function(e){var n,i=Z(e,null===(n=e.tagName)||void 0===n?void 0:n.toLowerCase());return!!i&&(t=i,!0)})),t},$=function(e,t){return s(["checkbox","radio"],e.type)?"".concat(t).concat((n=e.checked,"boolean"===f(n)?"("+e.checked+")":"")):t;var n},K=function e(t,r,o,a,d){void 0===a&&(a=!0),void 0===d&&(d=[]);var f=this;this.originNode=t,this.deviceInfo=r,this.actionType=o,this.trackable=a,this.parentNodes=d,this._getIndex=function(){if(I(f.originNode,C)){var e=T(f.originNode,C);return/^\d{1,10}$/.test(e)&&e-0>0&&2147483647>e-0?+e:void(0>f.actionType.indexOf("circle")&&(l="".concat(e,",index标记应为 大于 0 且小于 2147483647 的整数!"),"warn",console.log("%c [GrowingIO]:".concat(l),"color: #F59E0B;")))}if(s(["dd","dt"],f.tagName)){var t=X(f.originNode),i=t?D(t):[];if("dl"===t.tagName.toLowerCase()&&i.length>0){if("dd"===f.tagName){var r=u(i,(function(e){return e.isSameNode(f.originNode)}));if(r>-1)return(o=i.slice(0,r).filter((function(e){return"dt"===e.tagName.toLowerCase()}))).length-1+1}if("dt"===f.tagName){var o=i.filter((function(e){return"dt"===e.tagName.toLowerCase()}));return u(o,(function(e){return e.isSameNode(f.originNode)}))+1}}}if(f.isPureList){var a=u(f._pureList,(function(e){return e.isSameNode(f.originNode)}));return a>-1?(f.peerNodes=n([],f._pureList,!0),f.peerNodes.splice(a,1),a+1):void 0}if(f.isPseudoList){var c=u(f._pseudoList,(function(e){return e.isSameNode(f.originNode)}));return c>-1?(f.peerNodes=n([],f._pseudoList,!0),f.peerNodes.splice(c,1),c+1):void 0}var l},this._getSiblingNode=function(e,t){var n,r=X(e);if(!r)return[];for(var o=null!==(n=i((function(){return c(r.children)})))&&void 0!==n?n:[],a=[],u=0;ue.length||!s(m,f.tagName)||(f._pureList=e,0))},this._getIsInPseudoList=function(){if(s(["th","td"],f.tagName))return!1;var e=f._getSiblingNode(f.originNode,(function(e,t){var n=e.tagName===t.tagName&&e.className===t.className,i=D(e),r=D(t),o=i.every((function(e,t){var n,i;return(null==e?void 0:e.tagName)===(null===(n=r[t])||void 0===n?void 0:n.tagName)&&(null==e?void 0:e.className)===(null===(i=r[t])||void 0===i?void 0:i.className)})),a=i.length===r.length&&o;return n&&a}));return e.length>=3&&(f._pseudoList=e,!0)},this._getClassList=function(e){var t;if(I(e,"name")&&T(e,"name"))return[T(e,"name")];var n=(null!==(t=T(e,"class"))&&void 0!==t?t:"").trim().split(" ");return l(n)?[]:n.filter((function(e){return e&&!b.test(e)&&E.test(e)})).sort()},this._getCurrentXpath=function(){return"/".concat(f.tagName).concat(f.id?"#"+f.id:"").concat(l(f.classList)?"":"."+f.classList.join("."))},this._getIsContainer=function(){return I(f.originNode,_)||s(w,f.tagName)||"input"===f.tagName&&s(h,f.originNode.type)},this._getContent=function(){f.content=Z(f.originNode,f.tagName)},this._getIsOutFlow=function(){var e=window.getComputedStyle(f.originNode).position;return s(["fixed","sticky"],e)},this._getRect=function(){var e=f.originNode.getBoundingClientRect(),t=e.top,n=e.bottom,i=e.left,r=e.right-i,o=n-t;return t+o>f.deviceInfo.winHeight&&(o=f.deviceInfo.winHeight-t),i+r>f.deviceInfo.winWidth&&(r=f.deviceInfo.winWidth-i),{top:t,left:i,width:r,height:o}},this._getViewStatus=function(){var e=window.getComputedStyle(f.originNode),t=e.opacity,n=e.visibility,i=e.display,r=e.width,o=e.height,a=f.rect,u=a.top,s=a.left,c=a.width,l=a.height,d=f.deviceInfo,g=d.winWidth,h=d.winHeight;if(0===Number(t)||"hidden"===n||"none"===i||"0px"===r||"0px"===o)return"HIDDEN";var v=function(e,t){return document.elementFromPoint(e,t)===f.originNode};return h>u&&g>s&&c>0&&l>0?v(s+c/2,u+l/2)||v(s+1,u+1)||v(s+c-1,u+1)||v(s+1,u+l-1)||v(s+c-1,u+l-1)?"DISPLAYED":0>u+l||0>s+c?"OUTSIDE":"OBSCURED":"OUTSIDE"},this._getTriggerEvent=function(){return"input"===f.tagName&&s(N,f.originNode.type)||s(["select","textarea"],f.tagName)?"VIEW_CHANGE":"VIEW_CLICK"},this._getXParents=function(t,n){var i=t.parentElement,r=[];if(n.length>0)r.push.apply(r,n);else for(;i&&!H(i);)r.push(new e(i,void 0,f.actionType,S(i,f.actionType))),i=i.parentElement;return r},this.tagName=t.tagName.toLocaleLowerCase(),this.classList=this._getClassList(t),this.id=t.id,this.currentXpath=this._getCurrentXpath(),this.isIgnored=I(this.originNode,y),this.isContainer=this._getIsContainer(),this.isPureList=this._getIsPureList(),this.isPseudoList=this._getIsInPseudoList(),this.index=this._getIndex(),this.hyperlink=M(t,this.tagName),this.content=Z(this.originNode,this.tagName),this.triggerEvent=this._getTriggerEvent(),this.isOutFlow=this._getIsOutFlow(),r&&(this.rect=this._getRect(),this.viewStatus=this._getViewStatus()),this.xParents=this._getXParents(t,d)},q=function e(t,n,i,o,a){var u=this;this.origin=t,this.action=n,this.lengthThreshold=i,this.deviceInfo=o,this.parentNode=a,this.trackNodes=function(){var e;if(!u.trackable)return[];var t=[u.xNode];if(s(["click","circleClick","change"],u.actionType))for(var n=u._getParent();n;){if(!(null==n?void 0:n.xNode)||(null===(e=n.xNode)||void 0===e?void 0:e.isIgnored))return[];n.trackable&&t.push(n.xNode),n=n._getParent()}var i,o=[];return t.reverse().forEach((function(e,n){if(I(e.originNode,_)&&(o=[],i=void 0),r(e.index)&&!r(i)&&(i=e.index),r(i)&&(e.index=i),n===t.length-1)o.push(u.getGioNodeInfo(e));else{var a=e.isPureList||e.isPseudoList;(e.isContainer||a)&&o.push(u.getGioNodeInfo(e))}})),o},this.getGioNodeInfo=function(e){var t=u.computeXpath(e),n=t.skeleton,i=t.fullXpath,r=t.xpath,o=t.xcontent,a=e.hyperlink,s=e.index,c=e.peerNodes,l=e.content,d=e.triggerEvent,f=e.originNode;return{skeleton:n,fullXpath:i,xpath:r,xcontent:o,hyperlink:a,index:s,peerNodes:null!=c?c:[],content:B(l),triggerEvent:d,originNode:f}},this.computeXpath=function(e){var t,n="/"+e.tagName,i=e.currentXpath,r=e.currentXpath,o="/"+((e.id?"#"+e.id:"")+(l(e.classList)?"":"."+e.classList.join("."))||"-");return null===(t=e.xParents)||void 0===t||t.forEach((function(e,t){if(i=e.currentXpath+i,t-1||(null===(a=null==e?void 0:e.id)||void 0===a?void 0:a.indexOf("__giokit"))>-1)return!1;var c=new q(e,"circleClick",f.xpathThreshold,f.deviceInfo,n),d=c.xNode;if(d.zLevel=f._getZLevel(e,t),c.trackable&&s(["DISPLAYED","OBSCURED"],d.viewStatus)){if(t.index&&(d.index=t.index),"DISPLAYED"===d.viewStatus){var g=f._getGioHybridNodeInfo(c,t);J.push(g)}else"OBSCURED"===d.viewStatus&&d.isContainer&&(g=f._getGioHybridNodeInfo(c,t),J.push(g));if(G(e)||d.isContainer&&z(e))return!1}l(D(e))||f._getTrackElements(e,null!==(u=c.xNode)&&void 0!==u?u:t,c)}))},this._getZLevel=function(e,t){var n=window.getComputedStyle(e),i=n.position,r=n.zIndex;if("auto"!==r){var o=Number(r||0);return(Number.isNaN(o)?0:o)+t.zLevel}switch(i){case"relative":return t.zLevel+2;case"sticky":return t.zLevel+3;case"absolute":return t.zLevel+4;case"fixed":return t.zLevel+5;default:return t.zLevel+1}},this._getGioHybridNodeInfo=function(e,n){var i=e.xNode,r=i.rect,o=i.zLevel,a=e.getGioNodeInfo(i),u=a.hyperlink;return t(t(t({},r),a),{zLevel:o+f.deviceInfo.webviewZLevel,href:u,parentXPath:n.trackable?e.computeXpath(n).xpath:void 0})},this.xpathThreshold=n,this.deviceInfo=(r=(i=e).webviewLeft,o=i.webviewTop,a=i.webviewWidth,u=i.webviewHeight,c=i.webviewZLevel,{winWidth:d=document.documentElement.clientWidth,winHeight:document.documentElement.clientHeight,scale:a/d,webviewTop:o,webviewLeft:r,webviewWidth:a,webviewHeight:u,webviewZLevel:c})};export{Q as GioHybridNode,q as GioWebNode}; +import e from"array-from";var t=function(){return t=Object.assign||function(e){for(var t,n=1,i=arguments.length;i>n;n++)for(var r in t=arguments[n])({}).hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},t.apply(this,arguments)};function n(e,t,n){if(n||2===arguments.length)for(var i,r=0,o=t.length;o>r;r++)!i&&r in t||(i||(i=[].slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||[].slice.call(t))}var i=function(e){try{return e()}catch(e){return}},r=function(e){return"number"===g(e)},o=function(e){return"object"===g(e)&&!function(e){return s(["undefined","null"],g(e))}(e)},a=function(e){return Array.isArray(e)&&"array"===g(e)},u=function(e,t){var n=-1;if(a(e))for(var i=0;i=0},c=e,l=function(e){return o(e)?Object.keys(e):[]},d=function(e){return a(e)?0===e.length:o(e)?0===l(e).length:!e},f=function(e){if(a(e)){for(var t=0,n=[],i=0,r=e;it;if(n>t)return!0;for(var i=0;i0?t:void 0):""},M=/[^/]*.(bmp|jpg|jpeg|png|gif|svg|psd|webp|apng)/gi,R=function(e,t){switch(t){case"a":return function(e){if(T(e,"href")){var t=O(e,"href");if(t&&0!==t.indexOf("javascript"))return t.slice(0,320)}return""}(e);case"img":return function(e){var t=e.src;if(t&&-1===t.indexOf("data:image")){var n=t.match(M),i=d(n)?"":n[0];if(i.indexOf("%")>-1){var r=function(e,t){var n=-1;if(a(e))for(var i=0;i0&&t.every((function(e){return function(e){if("svg"===e.tagName)return!0;var t=X(e);if(d(t))return!0;var n=G(e);return!(!d(t)&&!n)}(e)}))}(e)&&!z(e)?F(Y(e)):z(e)?F($(e)):""},V=function(e,t){for(var n=e.parentElement;n&&!j(n);){if(t(n))return n;n=n.parentElement}},Y=function(e){var t=X(e);return f(t.map((function(e){var t=B(e);if(G(e)&&t)return t}))).join(" ")},$=function(e){var t;return X(e).some((function(e){var n,i=U(e,null===(n=e.tagName)||void 0===n?void 0:n.toLowerCase());return!!i&&(t=i,!0)})),t},K=function(e,t){return s(["checkbox","radio"],e.type)?"".concat(t).concat((n=e.checked,"boolean"===g(n)?"("+e.checked+")":"")):t;var n},q=function e(t,r,o,a,l){void 0===a&&(a=!0),void 0===l&&(l=[]);var f=this;this.originNode=t,this.deviceInfo=r,this.actionType=o,this.trackable=a,this.parentNodes=l,this._getIndex=function(){if(T(f.originNode,k)){var e=O(f.originNode,k);return/^\d{1,10}$/.test(e)&&e-0>0&&2147483647>e-0?+e:void(0>f.actionType.indexOf("circle")&&(l="".concat(e,",index标记应为 大于 0 且小于 2147483647 的整数!"),"warn",console.log("%c [GrowingIO]:".concat(l),"color: #F59E0B;")))}if(s(["dd","dt"],f.tagName)){var t=H(f.originNode),i=t?X(t):[];if("dl"===t.tagName.toLowerCase()&&i.length>0){if("dd"===f.tagName){var r=u(i,(function(e){return e.isSameNode(f.originNode)}));if(r>-1)return(o=i.slice(0,r).filter((function(e){return"dt"===e.tagName.toLowerCase()}))).length-1+1}if("dt"===f.tagName){var o=i.filter((function(e){return"dt"===e.tagName.toLowerCase()}));return u(o,(function(e){return e.isSameNode(f.originNode)}))+1}}}if(f.isPureList){var a=u(f._pureList,(function(e){return e.isSameNode(f.originNode)}));return a>-1?(f.peerNodes=n([],f._pureList,!0),f.peerNodes.splice(a,1),a+1):void 0}if(f.isPseudoList){var c=u(f._pseudoList,(function(e){return e.isSameNode(f.originNode)}));return c>-1?(f.peerNodes=n([],f._pseudoList,!0),f.peerNodes.splice(c,1),c+1):void 0}var l},this._getSiblingNode=function(e,t){var n,r=H(e);if(!r)return[];for(var o=null!==(n=i((function(){return c(r.children)})))&&void 0!==n?n:[],a=[],u=0;ue.length||!s(w,f.tagName)||(f._pureList=e,0))},this._getIsInPseudoList=function(){if(s(["th","td"],f.tagName))return!1;var e=f._getSiblingNode(f.originNode,(function(e,t){var n=e.tagName===t.tagName&&e.className===t.className,i=X(e),r=X(t),o=i.every((function(e,t){var n,i;return(null==e?void 0:e.tagName)===(null===(n=r[t])||void 0===n?void 0:n.tagName)&&(null==e?void 0:e.className)===(null===(i=r[t])||void 0===i?void 0:i.className)})),a=i.length===r.length&&o;return n&&a}));return e.length>=3&&(f._pseudoList=e,!0)},this._getClassList=function(e){var t;if(T(e,"name")&&O(e,"name"))return[O(e,"name")];var n=(null!==(t=O(e,"class"))&&void 0!==t?t:"").trim().split(" ");return d(n)?[]:n.filter((function(e){return e&&!y.test(e)&&E.test(e)})).sort()},this._getCurrentXpath=function(){return"/".concat(f.tagName).concat(f.id?"#"+f.id:"").concat(d(f.classList)?"":"."+f.classList.join("."))},this._getIsContainer=function(){return T(f.originNode,C)||s(L,f.tagName)||"input"===f.tagName&&s(v,f.originNode.type)},this._getContent=function(){f.content=U(f.originNode,f.tagName)},this._getIsOutFlow=function(){var e=window.getComputedStyle(f.originNode).position;return s(["fixed","sticky"],e)},this._getRect=function(){var e=f.originNode.getBoundingClientRect(),t=e.top,n=e.bottom,i=e.left,r=e.right-i,o=n-t,a=f.deviceInfo,u=a.winHeight,s=a.winWidth;return t+o>u&&(o=u-t),i+r>s&&(r=s-i),{top:t,left:i,width:r,height:o}},this._getViewStatus=function(){var e=window.getComputedStyle(f.originNode),t=e.opacity,n=e.visibility,i=e.display,r=e.width,o=e.height,a=f.rect,u=a.top,s=a.left,c=a.width,l=a.height,d=f.deviceInfo,g=d.winWidth,h=d.winHeight;if(0===Number(t)||"hidden"===n||"none"===i||"0px"===r||"0px"===o)return"HIDDEN";var v=function(e,t){return document.elementFromPoint(e,t)===f.originNode};return h>u&&g>s&&c>0&&l>0?v(s+c/2,u+l/2)||v(s+1,u+1)||v(s+c-1,u+1)||v(s+1,u+l-1)||v(s+c-1,u+l-1)?"DISPLAYED":0>u+l||0>s+c?"OUTSIDE":"OBSCURED":"OUTSIDE"},this._getTriggerEvent=function(){return"input"===f.tagName&&s(m,f.originNode.type)||s(["select","textarea"],f.tagName)?"VIEW_CHANGE":"VIEW_CLICK"},this._getXParents=function(t,n){var i=t.parentElement,r=[];if(n.length>0)r.push.apply(r,n);else for(;i&&!j(i);)r.push(new e(i,void 0,f.actionType,D(i,f.actionType))),i=i.parentElement;return r},this.tagName=t.tagName.toLocaleLowerCase(),this.classList=this._getClassList(t),this.id=t.id,this.currentXpath=this._getCurrentXpath(),this.isIgnored=T(this.originNode,_),this.isContainer=this._getIsContainer(),this.isPureList=this._getIsPureList(),this.isPseudoList=this._getIsInPseudoList(),this.index=this._getIndex(),this.hyperlink=R(t,this.tagName),this.content=U(this.originNode,this.tagName),this.triggerEvent=this._getTriggerEvent(),this.isOutFlow=this._getIsOutFlow(),r&&(this.rect=this._getRect(),this.viewStatus=this._getViewStatus()),this.xParents=this._getXParents(t,l)},J=function e(t,n,i,o,a){var u=this;this.origin=t,this.action=n,this.lengthThreshold=i,this.deviceInfo=o,this.parentNode=a,this.trackNodes=function(){var e;if(!u.trackable)return[];var t=[u.xNode];if(s(["click","circleClick","change"],u.actionType))for(var n=u._getParent();n;){if(!(null==n?void 0:n.xNode)||(null===(e=n.xNode)||void 0===e?void 0:e.isIgnored))return[];n.trackable&&t.push(n.xNode),n=n._getParent()}var i,o=[];return t.reverse().forEach((function(e,n){if(T(e.originNode,C)&&(o=[],i=void 0),r(e.index)&&!r(i)&&(i=e.index),r(i)&&(e.index=i),n===t.length-1)o.push(u.getGioNodeInfo(e));else{var a=e.isPureList||e.isPseudoList;(e.isContainer||a)&&o.push(u.getGioNodeInfo(e))}})),o},this.getGioNodeInfo=function(e){var t=u.computeXpath(e),n=t.skeleton,i=t.fullXpath,r=t.xpath,o=t.xcontent,a=e.hyperlink,s=e.index,c=e.peerNodes,l=e.content,d=e.triggerEvent,f=e.originNode;return{skeleton:n,fullXpath:i,xpath:r,xcontent:o,hyperlink:a,index:s,peerNodes:null!=c?c:[],content:F(l),triggerEvent:d,originNode:f}},this.computeXpath=function(e){var t,n="/"+e.tagName,i=e.currentXpath,r=e.currentXpath,o="/"+((e.id?"#"+e.id:"")+(d(e.classList)?"":"."+e.classList.join("."))||"-");return null===(t=e.xParents)||void 0===t||t.forEach((function(e,t){if(i=e.currentXpath+i,t-1||(null===(a=null==e?void 0:e.id)||void 0===a?void 0:a.indexOf("__giokit"))>-1)return!1;var c=new J(e,"circleClick",g.xpathThreshold,g.deviceInfo,n),l=c.xNode;if(l.zLevel=g._getZLevel(e,t),c.trackable&&s(["DISPLAYED","OBSCURED"],l.viewStatus)){if(t.index&&(l.index=t.index),"DISPLAYED"===l.viewStatus){var f=g._getGioHybridNodeInfo(c,t);Q.push(f)}else"OBSCURED"===l.viewStatus&&l.isContainer&&(f=g._getGioHybridNodeInfo(c,t),Q.push(f));if(W(e)||l.isContainer&&G(e))return!1}d(X(e))||g._getTrackElements(e,null!==(u=c.xNode)&&void 0!==u?u:t,c)}))},this._getZLevel=function(e,t){var n=window.getComputedStyle(e),i=n.position,r=n.zIndex;if("auto"!==r){var o=Number(r||0);return(Number.isNaN(o)?0:o)+t.zLevel}switch(i){case"relative":return t.zLevel+2;case"sticky":return t.zLevel+3;case"absolute":return t.zLevel+4;case"fixed":return t.zLevel+5;default:return t.zLevel+1}},this._getGioHybridNodeInfo=function(e,n){var i=e.xNode,r=i.rect,o=i.zLevel,a=e.getGioNodeInfo(i),u=a.hyperlink,s={};return l(r).forEach((function(e){return s[e]=r[e]*g.deviceInfo.scale})),t(t(t({},s),a),{zLevel:o+g.deviceInfo.webviewZLevel,href:u,parentXPath:n.trackable?e.computeXpath(n).xpath:void 0})},this.xpathThreshold=n,this.deviceInfo=(r=(i=e).webviewLeft,o=i.webviewTop,a=i.webviewWidth,u=i.webviewHeight,c=i.webviewZLevel,f=a/window.innerWidth,{winWidth:window.innerWidth,winHeight:window.innerHeight,scale:f,webviewTop:o,webviewLeft:r,webviewWidth:a,webviewHeight:u,webviewZLevel:c})};export{ee as GioHybridNode,J as GioWebNode};