@xm-fe/xm-h5-exposure
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -57,5 +57,5 @@ // polyfill | ||
this._observer = new IntersectionObserver( | ||
(entries, observer) => { | ||
entries.forEach((entry, idx) => { | ||
const pageName = window._xmLog.getCurrentPageName(); | ||
entries => { | ||
const pageName = window._xmLog.getCurrentPageName(); | ||
entries.forEach(entry => { | ||
if (!this.tagTime) { | ||
@@ -62,0 +62,0 @@ // 初始化一个标记时间点,为了后面计算定时曝光(在页面上展示超过一段时间就上传曝光信息,而不用等其从屏幕消失) |
/*! @xm-fe/xm-h5-exposure 0.0.1 */ | ||
function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,o(n.key),n)}}function i(t,e,i){return(e=o(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function o(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var o=i.call(t,e||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}!function(){if("object"===("undefined"==typeof window?"undefined":t(window)))if("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)"isIntersecting"in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return this.intersectionRatio>0}});else{var e=function(t){for(var e=window.document,i=r(e);i;)i=r(e=i.ownerDocument);return e}(),i=[],o=null,n=null;a.prototype.THROTTLE_TIMEOUT=100,a.prototype.POLL_INTERVAL=null,a.prototype.USE_MUTATION_OBSERVER=!0,a._setupCrossOriginUpdater=function(){return o||(o=function(t,e){n=t&&e?f(t,e):{top:0,bottom:0,left:0,right:0,width:0,height:0},i.forEach((function(t){t._checkForIntersections()}))}),o},a._resetCrossOriginUpdater=function(){o=null,n=null},a.prototype.observe=function(t){if(!this._observationTargets.some((function(e){return e.element==t}))){if(!t||1!=t.nodeType)throw new Error("target must be an Element");this._registerInstance(),this._observationTargets.push({element:t,entry:null}),this._monitorIntersections(t.ownerDocument),this._checkForIntersections()}},a.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter((function(e){return e.element!=t})),this._unmonitorIntersections(t.ownerDocument),0==this._observationTargets.length&&this._unregisterInstance()},a.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorAllIntersections(),this._unregisterInstance()},a.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},a.prototype._initThresholds=function(t){var e=t||[0];return Array.isArray(e)||(e=[e]),e.sort().filter((function(t,e,i){if("number"!=typeof t||isNaN(t)||t<0||t>1)throw new Error("threshold must be a number between 0 and 1 inclusively");return t!==i[e-1]}))},a.prototype._parseRootMargin=function(t){var e=(t||"0px").split(/\s+/).map((function(t){var e=/^(-?\d*\.?\d+)(px|%)$/.exec(t);if(!e)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(e[1]),unit:e[2]}}));return e[1]=e[1]||e[0],e[2]=e[2]||e[0],e[3]=e[3]||e[1],e},a.prototype._monitorIntersections=function(t){var i=t.defaultView;if(i&&-1==this._monitoringDocuments.indexOf(t)){var o=this._checkForIntersections,n=null,s=null;this.POLL_INTERVAL?n=i.setInterval(o,this.POLL_INTERVAL):(u(i,"resize",o,!0),u(t,"scroll",o,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in i&&(s=new i.MutationObserver(o)).observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0})),this._monitoringDocuments.push(t),this._monitoringUnsubscribes.push((function(){var e=t.defaultView;e&&(n&&e.clearInterval(n),h(e,"resize",o,!0)),h(t,"scroll",o,!0),s&&s.disconnect()}));var a=this.root&&(this.root.ownerDocument||this.root)||e;if(t!=a){var c=r(t);c&&this._monitorIntersections(c.ownerDocument)}}},a.prototype._unmonitorIntersections=function(t){var i=this._monitoringDocuments.indexOf(t);if(-1!=i){var o=this.root&&(this.root.ownerDocument||this.root)||e,n=this._observationTargets.some((function(e){var i=e.element.ownerDocument;if(i==t)return!0;for(;i&&i!=o;){var n=r(i);if((i=n&&n.ownerDocument)==t)return!0}return!1}));if(!n){var s=this._monitoringUnsubscribes[i];if(this._monitoringDocuments.splice(i,1),this._monitoringUnsubscribes.splice(i,1),s(),t!=o){var a=r(t);a&&this._unmonitorIntersections(a.ownerDocument)}}}},a.prototype._unmonitorAllIntersections=function(){var t=this._monitoringUnsubscribes.slice(0);this._monitoringDocuments.length=0,this._monitoringUnsubscribes.length=0;for(var e=0;e<t.length;e++)t[e]()},a.prototype._checkForIntersections=function(){if(this.root||!o||n){var t=this._rootIsInDom(),e=t?this._getRootRect():{top:0,bottom:0,left:0,right:0,width:0,height:0};this._observationTargets.forEach((function(i){var n=i.element,r=c(n),a=this._rootContainsTarget(n),u=i.entry,h=t&&a&&this._computeTargetAndRootIntersection(n,r,e),l=null;this._rootContainsTarget(n)?o&&!this.root||(l=e):l={top:0,bottom:0,left:0,right:0,width:0,height:0};var f=i.entry=new s({time:window.performance&&performance.now&&performance.now(),target:n,boundingClientRect:r,rootBounds:l,intersectionRect:h});u?t&&a?this._hasCrossedThreshold(u,f)&&this._queuedEntries.push(f):u&&u.isIntersecting&&this._queuedEntries.push(f):this._queuedEntries.push(f)}),this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)}},a.prototype._computeTargetAndRootIntersection=function(t,i,r){if("none"!=window.getComputedStyle(t).display){for(var s,a,u,h,l,d,m,g,v=i,b=p(t),w=!1;!w&&b;){var T=null,y=1==b.nodeType?window.getComputedStyle(b):{};if("none"==y.display)return null;if(b==this.root||9==b.nodeType)if(w=!0,b==this.root||b==e)o&&!this.root?!n||0==n.width&&0==n.height?(b=null,T=null,v=null):T=n:T=r;else{var _=p(b),I=_&&c(_),E=_&&this._computeTargetAndRootIntersection(_,I,r);I&&E?(b=_,T=f(I,E)):(b=null,v=null)}else{var M=b.ownerDocument;b!=M.body&&b!=M.documentElement&&"visible"!=y.overflow&&(T=c(b))}if(T&&(s=T,a=v,u=void 0,h=void 0,l=void 0,d=void 0,m=void 0,g=void 0,u=Math.max(s.top,a.top),h=Math.min(s.bottom,a.bottom),l=Math.max(s.left,a.left),d=Math.min(s.right,a.right),g=h-u,v=(m=d-l)>=0&&g>=0&&{top:u,bottom:h,left:l,right:d,width:m,height:g}||null),!v)break;b=b&&p(b)}return v}},a.prototype._getRootRect=function(){var t;if(this.root&&!m(this.root))t=c(this.root);else{var i=m(this.root)?this.root:e,o=i.documentElement,n=i.body;t={top:0,left:0,right:o.clientWidth||n.clientWidth,width:o.clientWidth||n.clientWidth,bottom:o.clientHeight||n.clientHeight,height:o.clientHeight||n.clientHeight}}return this._expandRectByRootMargin(t)},a.prototype._expandRectByRootMargin=function(t){var e=this._rootMarginValues.map((function(e,i){return"px"==e.unit?e.value:e.value*(i%2?t.width:t.height)/100})),i={top:t.top-e[0],right:t.right+e[1],bottom:t.bottom+e[2],left:t.left-e[3]};return i.width=i.right-i.left,i.height=i.bottom-i.top,i},a.prototype._hasCrossedThreshold=function(t,e){var i=t&&t.isIntersecting?t.intersectionRatio||0:-1,o=e.isIntersecting?e.intersectionRatio||0:-1;if(i!==o)for(var n=0;n<this.thresholds.length;n++){var r=this.thresholds[n];if(r==i||r==o||r<i!=r<o)return!0}},a.prototype._rootIsInDom=function(){return!this.root||d(e,this.root)},a.prototype._rootContainsTarget=function(t){var i=this.root&&(this.root.ownerDocument||this.root)||e;return d(i,t)&&(!this.root||i==t.ownerDocument)},a.prototype._registerInstance=function(){i.indexOf(this)<0&&i.push(this)},a.prototype._unregisterInstance=function(){var t=i.indexOf(this);-1!=t&&i.splice(t,1)},window.IntersectionObserver=a,window.IntersectionObserverEntry=s}function r(t){try{return t.defaultView&&t.defaultView.frameElement||null}catch(t){return null}}function s(t){this.time=t.time,this.target=t.target,this.rootBounds=l(t.rootBounds),this.boundingClientRect=l(t.boundingClientRect),this.intersectionRect=l(t.intersectionRect||{top:0,bottom:0,left:0,right:0,width:0,height:0}),this.isIntersecting=!!t.intersectionRect;var e=this.boundingClientRect,i=e.width*e.height,o=this.intersectionRect,n=o.width*o.height;this.intersectionRatio=i?Number((n/i).toFixed(4)):this.isIntersecting?1:0}function a(t,e){var i,o,n,r=e||{};if("function"!=typeof t)throw new Error("callback must be a function");if(r.root&&1!=r.root.nodeType&&9!=r.root.nodeType)throw new Error("root must be a Document or Element");this._checkForIntersections=(i=this._checkForIntersections.bind(this),o=this.THROTTLE_TIMEOUT,n=null,function(){n||(n=setTimeout((function(){i(),n=null}),o))}),this._callback=t,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(r.rootMargin),this.thresholds=this._initThresholds(r.threshold),this.root=r.root||null,this.rootMargin=this._rootMarginValues.map((function(t){return t.value+t.unit})).join(" "),this._monitoringDocuments=[],this._monitoringUnsubscribes=[]}function u(t,e,i,o){"function"==typeof t.addEventListener?t.addEventListener(e,i,o||!1):"function"==typeof t.attachEvent&&t.attachEvent("on"+e,i)}function h(t,e,i,o){"function"==typeof t.removeEventListener?t.removeEventListener(e,i,o||!1):"function"==typeof t.detachEvent&&t.detachEvent("on"+e,i)}function c(t){var e;try{e=t.getBoundingClientRect()}catch(t){}return e?(e.width&&e.height||(e={top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:e.right-e.left,height:e.bottom-e.top}),e):{top:0,bottom:0,left:0,right:0,width:0,height:0}}function l(t){return!t||"x"in t?t:{top:t.top,y:t.top,bottom:t.bottom,left:t.left,x:t.left,right:t.right,width:t.width,height:t.height}}function f(t,e){var i=e.top-t.top,o=e.left-t.left;return{top:i,left:o,height:e.height,width:e.width,bottom:i+e.height,right:o+e.width}}function d(t,e){for(var i=e;i;){if(i==t)return!0;i=p(i)}return!1}function p(t){var i=t.parentNode;return 9==t.nodeType&&t!=e?r(t):(i&&i.assignedSlot&&(i=i.assignedSlot.parentNode),i&&11==i.nodeType&&i.host?i.host:i)}function m(t){return t&&9===t.nodeType}}(),window.IntersectionObserver&&(IntersectionObserver.prototype.THROTTLE_TIMEOUT=350);var n=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),i(this,"_observer",void 0),i(this,"dotMap",void 0),i(this,"currentTrickDotArr",void 0),i(this,"currentTrickLogArr",void 0),i(this,"tagTime",void 0),i(this,"tagDateTime",void 0),this.dotMap={},this.currentTrickDotArr=[],this.currentTrickLogArr=[],this.init()}var o,n,r;return o=t,(n=[{key:"init",value:function(){var e=this;this._observer=new IntersectionObserver((function(t,i){t.forEach((function(t,i){var o=window._xmLog.getCurrentPageName();e.tagTime||(e.tagTime=t.time,e.tagDateTime=Date.now());var n={id:e.getId(t.target),pageName:o};t.isIntersecting?n.startTime=t.time:n.endTime=t.time,e.currentTrickDotArr.push(n)}))}),{root:null,rootMargin:"0px",threshold:.5}),setInterval((function(){var i="";e.currentTrickDotArr.forEach((function(o){var n=o.id,r=o.startTime,s=o.endTime,a=o.pageName;if(r)e.dotMap[n]?(e.dotMap[n].startTime=r,e.dotMap[n].pageName=a,e.dotMap[n].state="waiting"):e.dotMap[n]={id:n,startTime:r,state:"waiting",endTime:-t.waitTime,pageName:a};else if(e.dotMap[n]&&"waiting"==e.dotMap[n].state){var u=e.dotMap[n];s-u.startTime>t.viewTime&&s-u.endTime>t.waitTime&&(i=e.dotMap[n].pageName,e.currentTrickLogArr.push(n),e.dotMap[n].endTime=s),e.dotMap[n].startTime=0,e.dotMap[n].state="init"}}));var o=Date.now();Object.values(e.dotMap).forEach((function(n){var r=n.id,s=n.startTime,a=n.state,u=n.endTime;if("waiting"===a){var h=o-e.tagDateTime-s+e.tagTime,c=s+h;h>t.viewTime&&c-u>t.waitTime&&(i=e.dotMap[r].pageName,e.currentTrickLogArr.push(r),e.dotMap[r].endTime=c,e.dotMap[r].startTime=0,e.dotMap[r].state="init")}})),e.currentTrickLogArr.length&&e.log(e.currentTrickLogArr,i),e.currentTrickDotArr=[],e.currentTrickLogArr=[]}),t.checkTime)}},{key:"bind",value:function(t){this._observer&&this._observer.observe(t)}},{key:"unbind",value:function(t){var e=this.getId(t);delete this.dotMap[e],this._observer&&this._observer.unobserve(t)}},{key:"getId",value:function(t){var e=t.attributes["data-xm"];return(e?e.value:t.attributes["data-xmv"].value).split(",").map((function(t){return t.split(":")[1]})).join()}},{key:"log",value:function(t,e){var i,o;null===(i=window)||void 0===i||null===(o=i._xmLog)||void 0===o||o.viewLog(t.join(";"),{pageName:e})}}])&&e(o.prototype,n),r&&e(o,r),Object.defineProperty(o,"prototype",{writable:!1}),t}();i(n,"viewTime",1e3),i(n,"waitTime",15e3),i(n,"checkTime",400);export{n as Exposure}; | ||
function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,o(n.key),n)}}function i(t,e,i){return(e=o(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function o(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var o=i.call(t,e||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}!function(){if("object"===("undefined"==typeof window?"undefined":t(window)))if("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)"isIntersecting"in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return this.intersectionRatio>0}});else{var e=function(t){for(var e=window.document,i=r(e);i;)i=r(e=i.ownerDocument);return e}(),i=[],o=null,n=null;a.prototype.THROTTLE_TIMEOUT=100,a.prototype.POLL_INTERVAL=null,a.prototype.USE_MUTATION_OBSERVER=!0,a._setupCrossOriginUpdater=function(){return o||(o=function(t,e){n=t&&e?f(t,e):{top:0,bottom:0,left:0,right:0,width:0,height:0},i.forEach((function(t){t._checkForIntersections()}))}),o},a._resetCrossOriginUpdater=function(){o=null,n=null},a.prototype.observe=function(t){if(!this._observationTargets.some((function(e){return e.element==t}))){if(!t||1!=t.nodeType)throw new Error("target must be an Element");this._registerInstance(),this._observationTargets.push({element:t,entry:null}),this._monitorIntersections(t.ownerDocument),this._checkForIntersections()}},a.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter((function(e){return e.element!=t})),this._unmonitorIntersections(t.ownerDocument),0==this._observationTargets.length&&this._unregisterInstance()},a.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorAllIntersections(),this._unregisterInstance()},a.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},a.prototype._initThresholds=function(t){var e=t||[0];return Array.isArray(e)||(e=[e]),e.sort().filter((function(t,e,i){if("number"!=typeof t||isNaN(t)||t<0||t>1)throw new Error("threshold must be a number between 0 and 1 inclusively");return t!==i[e-1]}))},a.prototype._parseRootMargin=function(t){var e=(t||"0px").split(/\s+/).map((function(t){var e=/^(-?\d*\.?\d+)(px|%)$/.exec(t);if(!e)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(e[1]),unit:e[2]}}));return e[1]=e[1]||e[0],e[2]=e[2]||e[0],e[3]=e[3]||e[1],e},a.prototype._monitorIntersections=function(t){var i=t.defaultView;if(i&&-1==this._monitoringDocuments.indexOf(t)){var o=this._checkForIntersections,n=null,s=null;this.POLL_INTERVAL?n=i.setInterval(o,this.POLL_INTERVAL):(u(i,"resize",o,!0),u(t,"scroll",o,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in i&&(s=new i.MutationObserver(o)).observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0})),this._monitoringDocuments.push(t),this._monitoringUnsubscribes.push((function(){var e=t.defaultView;e&&(n&&e.clearInterval(n),h(e,"resize",o,!0)),h(t,"scroll",o,!0),s&&s.disconnect()}));var a=this.root&&(this.root.ownerDocument||this.root)||e;if(t!=a){var c=r(t);c&&this._monitorIntersections(c.ownerDocument)}}},a.prototype._unmonitorIntersections=function(t){var i=this._monitoringDocuments.indexOf(t);if(-1!=i){var o=this.root&&(this.root.ownerDocument||this.root)||e,n=this._observationTargets.some((function(e){var i=e.element.ownerDocument;if(i==t)return!0;for(;i&&i!=o;){var n=r(i);if((i=n&&n.ownerDocument)==t)return!0}return!1}));if(!n){var s=this._monitoringUnsubscribes[i];if(this._monitoringDocuments.splice(i,1),this._monitoringUnsubscribes.splice(i,1),s(),t!=o){var a=r(t);a&&this._unmonitorIntersections(a.ownerDocument)}}}},a.prototype._unmonitorAllIntersections=function(){var t=this._monitoringUnsubscribes.slice(0);this._monitoringDocuments.length=0,this._monitoringUnsubscribes.length=0;for(var e=0;e<t.length;e++)t[e]()},a.prototype._checkForIntersections=function(){if(this.root||!o||n){var t=this._rootIsInDom(),e=t?this._getRootRect():{top:0,bottom:0,left:0,right:0,width:0,height:0};this._observationTargets.forEach((function(i){var n=i.element,r=c(n),a=this._rootContainsTarget(n),u=i.entry,h=t&&a&&this._computeTargetAndRootIntersection(n,r,e),l=null;this._rootContainsTarget(n)?o&&!this.root||(l=e):l={top:0,bottom:0,left:0,right:0,width:0,height:0};var f=i.entry=new s({time:window.performance&&performance.now&&performance.now(),target:n,boundingClientRect:r,rootBounds:l,intersectionRect:h});u?t&&a?this._hasCrossedThreshold(u,f)&&this._queuedEntries.push(f):u&&u.isIntersecting&&this._queuedEntries.push(f):this._queuedEntries.push(f)}),this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)}},a.prototype._computeTargetAndRootIntersection=function(t,i,r){if("none"!=window.getComputedStyle(t).display){for(var s,a,u,h,l,d,m,g,v=i,b=p(t),w=!1;!w&&b;){var T=null,y=1==b.nodeType?window.getComputedStyle(b):{};if("none"==y.display)return null;if(b==this.root||9==b.nodeType)if(w=!0,b==this.root||b==e)o&&!this.root?!n||0==n.width&&0==n.height?(b=null,T=null,v=null):T=n:T=r;else{var _=p(b),I=_&&c(_),E=_&&this._computeTargetAndRootIntersection(_,I,r);I&&E?(b=_,T=f(I,E)):(b=null,v=null)}else{var M=b.ownerDocument;b!=M.body&&b!=M.documentElement&&"visible"!=y.overflow&&(T=c(b))}if(T&&(s=T,a=v,u=void 0,h=void 0,l=void 0,d=void 0,m=void 0,g=void 0,u=Math.max(s.top,a.top),h=Math.min(s.bottom,a.bottom),l=Math.max(s.left,a.left),d=Math.min(s.right,a.right),g=h-u,v=(m=d-l)>=0&&g>=0&&{top:u,bottom:h,left:l,right:d,width:m,height:g}||null),!v)break;b=b&&p(b)}return v}},a.prototype._getRootRect=function(){var t;if(this.root&&!m(this.root))t=c(this.root);else{var i=m(this.root)?this.root:e,o=i.documentElement,n=i.body;t={top:0,left:0,right:o.clientWidth||n.clientWidth,width:o.clientWidth||n.clientWidth,bottom:o.clientHeight||n.clientHeight,height:o.clientHeight||n.clientHeight}}return this._expandRectByRootMargin(t)},a.prototype._expandRectByRootMargin=function(t){var e=this._rootMarginValues.map((function(e,i){return"px"==e.unit?e.value:e.value*(i%2?t.width:t.height)/100})),i={top:t.top-e[0],right:t.right+e[1],bottom:t.bottom+e[2],left:t.left-e[3]};return i.width=i.right-i.left,i.height=i.bottom-i.top,i},a.prototype._hasCrossedThreshold=function(t,e){var i=t&&t.isIntersecting?t.intersectionRatio||0:-1,o=e.isIntersecting?e.intersectionRatio||0:-1;if(i!==o)for(var n=0;n<this.thresholds.length;n++){var r=this.thresholds[n];if(r==i||r==o||r<i!=r<o)return!0}},a.prototype._rootIsInDom=function(){return!this.root||d(e,this.root)},a.prototype._rootContainsTarget=function(t){var i=this.root&&(this.root.ownerDocument||this.root)||e;return d(i,t)&&(!this.root||i==t.ownerDocument)},a.prototype._registerInstance=function(){i.indexOf(this)<0&&i.push(this)},a.prototype._unregisterInstance=function(){var t=i.indexOf(this);-1!=t&&i.splice(t,1)},window.IntersectionObserver=a,window.IntersectionObserverEntry=s}function r(t){try{return t.defaultView&&t.defaultView.frameElement||null}catch(t){return null}}function s(t){this.time=t.time,this.target=t.target,this.rootBounds=l(t.rootBounds),this.boundingClientRect=l(t.boundingClientRect),this.intersectionRect=l(t.intersectionRect||{top:0,bottom:0,left:0,right:0,width:0,height:0}),this.isIntersecting=!!t.intersectionRect;var e=this.boundingClientRect,i=e.width*e.height,o=this.intersectionRect,n=o.width*o.height;this.intersectionRatio=i?Number((n/i).toFixed(4)):this.isIntersecting?1:0}function a(t,e){var i,o,n,r=e||{};if("function"!=typeof t)throw new Error("callback must be a function");if(r.root&&1!=r.root.nodeType&&9!=r.root.nodeType)throw new Error("root must be a Document or Element");this._checkForIntersections=(i=this._checkForIntersections.bind(this),o=this.THROTTLE_TIMEOUT,n=null,function(){n||(n=setTimeout((function(){i(),n=null}),o))}),this._callback=t,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(r.rootMargin),this.thresholds=this._initThresholds(r.threshold),this.root=r.root||null,this.rootMargin=this._rootMarginValues.map((function(t){return t.value+t.unit})).join(" "),this._monitoringDocuments=[],this._monitoringUnsubscribes=[]}function u(t,e,i,o){"function"==typeof t.addEventListener?t.addEventListener(e,i,o||!1):"function"==typeof t.attachEvent&&t.attachEvent("on"+e,i)}function h(t,e,i,o){"function"==typeof t.removeEventListener?t.removeEventListener(e,i,o||!1):"function"==typeof t.detachEvent&&t.detachEvent("on"+e,i)}function c(t){var e;try{e=t.getBoundingClientRect()}catch(t){}return e?(e.width&&e.height||(e={top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:e.right-e.left,height:e.bottom-e.top}),e):{top:0,bottom:0,left:0,right:0,width:0,height:0}}function l(t){return!t||"x"in t?t:{top:t.top,y:t.top,bottom:t.bottom,left:t.left,x:t.left,right:t.right,width:t.width,height:t.height}}function f(t,e){var i=e.top-t.top,o=e.left-t.left;return{top:i,left:o,height:e.height,width:e.width,bottom:i+e.height,right:o+e.width}}function d(t,e){for(var i=e;i;){if(i==t)return!0;i=p(i)}return!1}function p(t){var i=t.parentNode;return 9==t.nodeType&&t!=e?r(t):(i&&i.assignedSlot&&(i=i.assignedSlot.parentNode),i&&11==i.nodeType&&i.host?i.host:i)}function m(t){return t&&9===t.nodeType}}(),window.IntersectionObserver&&(IntersectionObserver.prototype.THROTTLE_TIMEOUT=350);var n=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),i(this,"_observer",void 0),i(this,"dotMap",void 0),i(this,"currentTrickDotArr",void 0),i(this,"currentTrickLogArr",void 0),i(this,"tagTime",void 0),i(this,"tagDateTime",void 0),this.dotMap={},this.currentTrickDotArr=[],this.currentTrickLogArr=[],this.init()}var o,n,r;return o=t,(n=[{key:"init",value:function(){var e=this;this._observer=new IntersectionObserver((function(t){var i=window._xmLog.getCurrentPageName();t.forEach((function(t){e.tagTime||(e.tagTime=t.time,e.tagDateTime=Date.now());var o={id:e.getId(t.target),pageName:i};t.isIntersecting?o.startTime=t.time:o.endTime=t.time,e.currentTrickDotArr.push(o)}))}),{root:null,rootMargin:"0px",threshold:.5}),setInterval((function(){var i="";e.currentTrickDotArr.forEach((function(o){var n=o.id,r=o.startTime,s=o.endTime,a=o.pageName;if(r)e.dotMap[n]?(e.dotMap[n].startTime=r,e.dotMap[n].pageName=a,e.dotMap[n].state="waiting"):e.dotMap[n]={id:n,startTime:r,state:"waiting",endTime:-t.waitTime,pageName:a};else if(e.dotMap[n]&&"waiting"==e.dotMap[n].state){var u=e.dotMap[n];s-u.startTime>t.viewTime&&s-u.endTime>t.waitTime&&(i=e.dotMap[n].pageName,e.currentTrickLogArr.push(n),e.dotMap[n].endTime=s),e.dotMap[n].startTime=0,e.dotMap[n].state="init"}}));var o=Date.now();Object.values(e.dotMap).forEach((function(n){var r=n.id,s=n.startTime,a=n.state,u=n.endTime;if("waiting"===a){var h=o-e.tagDateTime-s+e.tagTime,c=s+h;h>t.viewTime&&c-u>t.waitTime&&(i=e.dotMap[r].pageName,e.currentTrickLogArr.push(r),e.dotMap[r].endTime=c,e.dotMap[r].startTime=0,e.dotMap[r].state="init")}})),e.currentTrickLogArr.length&&e.log(e.currentTrickLogArr,i),e.currentTrickDotArr=[],e.currentTrickLogArr=[]}),t.checkTime)}},{key:"bind",value:function(t){this._observer&&this._observer.observe(t)}},{key:"unbind",value:function(t){var e=this.getId(t);delete this.dotMap[e],this._observer&&this._observer.unobserve(t)}},{key:"getId",value:function(t){var e=t.attributes["data-xm"];return(e?e.value:t.attributes["data-xmv"].value).split(",").map((function(t){return t.split(":")[1]})).join()}},{key:"log",value:function(t,e){var i,o;null===(i=window)||void 0===i||null===(o=i._xmLog)||void 0===o||o.viewLog(t.join(";"),{pageName:e})}}])&&e(o.prototype,n),r&&e(o,r),Object.defineProperty(o,"prototype",{writable:!1}),t}();i(n,"viewTime",1e3),i(n,"waitTime",15e3),i(n,"checkTime",400);export{n as Exposure}; |
/*! @xm-fe/xm-h5-exposure 0.0.1 */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["xm-h5-exposure"]={})}(this,(function(t){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function o(t,e){for(var o=0;o<e.length;o++){var i=e[o];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,n(i.key),i)}}function i(t,e,o){return(e=n(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function n(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var i=o.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}!function(){if("object"===("undefined"==typeof window?"undefined":e(window)))if("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)"isIntersecting"in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return this.intersectionRatio>0}});else{var t=function(t){for(var e=window.document,o=r(e);o;)o=r(e=o.ownerDocument);return e}(),o=[],i=null,n=null;a.prototype.THROTTLE_TIMEOUT=100,a.prototype.POLL_INTERVAL=null,a.prototype.USE_MUTATION_OBSERVER=!0,a._setupCrossOriginUpdater=function(){return i||(i=function(t,e){n=t&&e?f(t,e):{top:0,bottom:0,left:0,right:0,width:0,height:0},o.forEach((function(t){t._checkForIntersections()}))}),i},a._resetCrossOriginUpdater=function(){i=null,n=null},a.prototype.observe=function(t){if(!this._observationTargets.some((function(e){return e.element==t}))){if(!t||1!=t.nodeType)throw new Error("target must be an Element");this._registerInstance(),this._observationTargets.push({element:t,entry:null}),this._monitorIntersections(t.ownerDocument),this._checkForIntersections()}},a.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter((function(e){return e.element!=t})),this._unmonitorIntersections(t.ownerDocument),0==this._observationTargets.length&&this._unregisterInstance()},a.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorAllIntersections(),this._unregisterInstance()},a.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},a.prototype._initThresholds=function(t){var e=t||[0];return Array.isArray(e)||(e=[e]),e.sort().filter((function(t,e,o){if("number"!=typeof t||isNaN(t)||t<0||t>1)throw new Error("threshold must be a number between 0 and 1 inclusively");return t!==o[e-1]}))},a.prototype._parseRootMargin=function(t){var e=(t||"0px").split(/\s+/).map((function(t){var e=/^(-?\d*\.?\d+)(px|%)$/.exec(t);if(!e)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(e[1]),unit:e[2]}}));return e[1]=e[1]||e[0],e[2]=e[2]||e[0],e[3]=e[3]||e[1],e},a.prototype._monitorIntersections=function(e){var o=e.defaultView;if(o&&-1==this._monitoringDocuments.indexOf(e)){var i=this._checkForIntersections,n=null,s=null;this.POLL_INTERVAL?n=o.setInterval(i,this.POLL_INTERVAL):(u(o,"resize",i,!0),u(e,"scroll",i,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in o&&(s=new o.MutationObserver(i)).observe(e,{attributes:!0,childList:!0,characterData:!0,subtree:!0})),this._monitoringDocuments.push(e),this._monitoringUnsubscribes.push((function(){var t=e.defaultView;t&&(n&&t.clearInterval(n),c(t,"resize",i,!0)),c(e,"scroll",i,!0),s&&s.disconnect()}));var a=this.root&&(this.root.ownerDocument||this.root)||t;if(e!=a){var h=r(e);h&&this._monitorIntersections(h.ownerDocument)}}},a.prototype._unmonitorIntersections=function(e){var o=this._monitoringDocuments.indexOf(e);if(-1!=o){var i=this.root&&(this.root.ownerDocument||this.root)||t,n=this._observationTargets.some((function(t){var o=t.element.ownerDocument;if(o==e)return!0;for(;o&&o!=i;){var n=r(o);if((o=n&&n.ownerDocument)==e)return!0}return!1}));if(!n){var s=this._monitoringUnsubscribes[o];if(this._monitoringDocuments.splice(o,1),this._monitoringUnsubscribes.splice(o,1),s(),e!=i){var a=r(e);a&&this._unmonitorIntersections(a.ownerDocument)}}}},a.prototype._unmonitorAllIntersections=function(){var t=this._monitoringUnsubscribes.slice(0);this._monitoringDocuments.length=0,this._monitoringUnsubscribes.length=0;for(var e=0;e<t.length;e++)t[e]()},a.prototype._checkForIntersections=function(){if(this.root||!i||n){var t=this._rootIsInDom(),e=t?this._getRootRect():{top:0,bottom:0,left:0,right:0,width:0,height:0};this._observationTargets.forEach((function(o){var n=o.element,r=h(n),a=this._rootContainsTarget(n),u=o.entry,c=t&&a&&this._computeTargetAndRootIntersection(n,r,e),l=null;this._rootContainsTarget(n)?i&&!this.root||(l=e):l={top:0,bottom:0,left:0,right:0,width:0,height:0};var f=o.entry=new s({time:window.performance&&performance.now&&performance.now(),target:n,boundingClientRect:r,rootBounds:l,intersectionRect:c});u?t&&a?this._hasCrossedThreshold(u,f)&&this._queuedEntries.push(f):u&&u.isIntersecting&&this._queuedEntries.push(f):this._queuedEntries.push(f)}),this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)}},a.prototype._computeTargetAndRootIntersection=function(e,o,r){if("none"!=window.getComputedStyle(e).display){for(var s,a,u,c,l,d,m,g,v=o,b=p(e),w=!1;!w&&b;){var y=null,T=1==b.nodeType?window.getComputedStyle(b):{};if("none"==T.display)return null;if(b==this.root||9==b.nodeType)if(w=!0,b==this.root||b==t)i&&!this.root?!n||0==n.width&&0==n.height?(b=null,y=null,v=null):y=n:y=r;else{var _=p(b),I=_&&h(_),E=_&&this._computeTargetAndRootIntersection(_,I,r);I&&E?(b=_,y=f(I,E)):(b=null,v=null)}else{var M=b.ownerDocument;b!=M.body&&b!=M.documentElement&&"visible"!=T.overflow&&(y=h(b))}if(y&&(s=y,a=v,u=void 0,c=void 0,l=void 0,d=void 0,m=void 0,g=void 0,u=Math.max(s.top,a.top),c=Math.min(s.bottom,a.bottom),l=Math.max(s.left,a.left),d=Math.min(s.right,a.right),g=c-u,v=(m=d-l)>=0&&g>=0&&{top:u,bottom:c,left:l,right:d,width:m,height:g}||null),!v)break;b=b&&p(b)}return v}},a.prototype._getRootRect=function(){var e;if(this.root&&!m(this.root))e=h(this.root);else{var o=m(this.root)?this.root:t,i=o.documentElement,n=o.body;e={top:0,left:0,right:i.clientWidth||n.clientWidth,width:i.clientWidth||n.clientWidth,bottom:i.clientHeight||n.clientHeight,height:i.clientHeight||n.clientHeight}}return this._expandRectByRootMargin(e)},a.prototype._expandRectByRootMargin=function(t){var e=this._rootMarginValues.map((function(e,o){return"px"==e.unit?e.value:e.value*(o%2?t.width:t.height)/100})),o={top:t.top-e[0],right:t.right+e[1],bottom:t.bottom+e[2],left:t.left-e[3]};return o.width=o.right-o.left,o.height=o.bottom-o.top,o},a.prototype._hasCrossedThreshold=function(t,e){var o=t&&t.isIntersecting?t.intersectionRatio||0:-1,i=e.isIntersecting?e.intersectionRatio||0:-1;if(o!==i)for(var n=0;n<this.thresholds.length;n++){var r=this.thresholds[n];if(r==o||r==i||r<o!=r<i)return!0}},a.prototype._rootIsInDom=function(){return!this.root||d(t,this.root)},a.prototype._rootContainsTarget=function(e){var o=this.root&&(this.root.ownerDocument||this.root)||t;return d(o,e)&&(!this.root||o==e.ownerDocument)},a.prototype._registerInstance=function(){o.indexOf(this)<0&&o.push(this)},a.prototype._unregisterInstance=function(){var t=o.indexOf(this);-1!=t&&o.splice(t,1)},window.IntersectionObserver=a,window.IntersectionObserverEntry=s}function r(t){try{return t.defaultView&&t.defaultView.frameElement||null}catch(t){return null}}function s(t){this.time=t.time,this.target=t.target,this.rootBounds=l(t.rootBounds),this.boundingClientRect=l(t.boundingClientRect),this.intersectionRect=l(t.intersectionRect||{top:0,bottom:0,left:0,right:0,width:0,height:0}),this.isIntersecting=!!t.intersectionRect;var e=this.boundingClientRect,o=e.width*e.height,i=this.intersectionRect,n=i.width*i.height;this.intersectionRatio=o?Number((n/o).toFixed(4)):this.isIntersecting?1:0}function a(t,e){var o,i,n,r=e||{};if("function"!=typeof t)throw new Error("callback must be a function");if(r.root&&1!=r.root.nodeType&&9!=r.root.nodeType)throw new Error("root must be a Document or Element");this._checkForIntersections=(o=this._checkForIntersections.bind(this),i=this.THROTTLE_TIMEOUT,n=null,function(){n||(n=setTimeout((function(){o(),n=null}),i))}),this._callback=t,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(r.rootMargin),this.thresholds=this._initThresholds(r.threshold),this.root=r.root||null,this.rootMargin=this._rootMarginValues.map((function(t){return t.value+t.unit})).join(" "),this._monitoringDocuments=[],this._monitoringUnsubscribes=[]}function u(t,e,o,i){"function"==typeof t.addEventListener?t.addEventListener(e,o,i||!1):"function"==typeof t.attachEvent&&t.attachEvent("on"+e,o)}function c(t,e,o,i){"function"==typeof t.removeEventListener?t.removeEventListener(e,o,i||!1):"function"==typeof t.detachEvent&&t.detachEvent("on"+e,o)}function h(t){var e;try{e=t.getBoundingClientRect()}catch(t){}return e?(e.width&&e.height||(e={top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:e.right-e.left,height:e.bottom-e.top}),e):{top:0,bottom:0,left:0,right:0,width:0,height:0}}function l(t){return!t||"x"in t?t:{top:t.top,y:t.top,bottom:t.bottom,left:t.left,x:t.left,right:t.right,width:t.width,height:t.height}}function f(t,e){var o=e.top-t.top,i=e.left-t.left;return{top:o,left:i,height:e.height,width:e.width,bottom:o+e.height,right:i+e.width}}function d(t,e){for(var o=e;o;){if(o==t)return!0;o=p(o)}return!1}function p(e){var o=e.parentNode;return 9==e.nodeType&&e!=t?r(e):(o&&o.assignedSlot&&(o=o.assignedSlot.parentNode),o&&11==o.nodeType&&o.host?o.host:o)}function m(t){return t&&9===t.nodeType}}(),window.IntersectionObserver&&(IntersectionObserver.prototype.THROTTLE_TIMEOUT=350);var r=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),i(this,"_observer",void 0),i(this,"dotMap",void 0),i(this,"currentTrickDotArr",void 0),i(this,"currentTrickLogArr",void 0),i(this,"tagTime",void 0),i(this,"tagDateTime",void 0),this.dotMap={},this.currentTrickDotArr=[],this.currentTrickLogArr=[],this.init()}var e,n,r;return e=t,(n=[{key:"init",value:function(){var e=this;this._observer=new IntersectionObserver((function(t,o){t.forEach((function(t,o){var i=window._xmLog.getCurrentPageName();e.tagTime||(e.tagTime=t.time,e.tagDateTime=Date.now());var n={id:e.getId(t.target),pageName:i};t.isIntersecting?n.startTime=t.time:n.endTime=t.time,e.currentTrickDotArr.push(n)}))}),{root:null,rootMargin:"0px",threshold:.5}),setInterval((function(){var o="";e.currentTrickDotArr.forEach((function(i){var n=i.id,r=i.startTime,s=i.endTime,a=i.pageName;if(r)e.dotMap[n]?(e.dotMap[n].startTime=r,e.dotMap[n].pageName=a,e.dotMap[n].state="waiting"):e.dotMap[n]={id:n,startTime:r,state:"waiting",endTime:-t.waitTime,pageName:a};else if(e.dotMap[n]&&"waiting"==e.dotMap[n].state){var u=e.dotMap[n];s-u.startTime>t.viewTime&&s-u.endTime>t.waitTime&&(o=e.dotMap[n].pageName,e.currentTrickLogArr.push(n),e.dotMap[n].endTime=s),e.dotMap[n].startTime=0,e.dotMap[n].state="init"}}));var i=Date.now();Object.values(e.dotMap).forEach((function(n){var r=n.id,s=n.startTime,a=n.state,u=n.endTime;if("waiting"===a){var c=i-e.tagDateTime-s+e.tagTime,h=s+c;c>t.viewTime&&h-u>t.waitTime&&(o=e.dotMap[r].pageName,e.currentTrickLogArr.push(r),e.dotMap[r].endTime=h,e.dotMap[r].startTime=0,e.dotMap[r].state="init")}})),e.currentTrickLogArr.length&&e.log(e.currentTrickLogArr,o),e.currentTrickDotArr=[],e.currentTrickLogArr=[]}),t.checkTime)}},{key:"bind",value:function(t){this._observer&&this._observer.observe(t)}},{key:"unbind",value:function(t){var e=this.getId(t);delete this.dotMap[e],this._observer&&this._observer.unobserve(t)}},{key:"getId",value:function(t){var e=t.attributes["data-xm"];return(e?e.value:t.attributes["data-xmv"].value).split(",").map((function(t){return t.split(":")[1]})).join()}},{key:"log",value:function(t,e){var o,i;null===(o=window)||void 0===o||null===(i=o._xmLog)||void 0===i||i.viewLog(t.join(";"),{pageName:e})}}])&&o(e.prototype,n),r&&o(e,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();i(r,"viewTime",1e3),i(r,"waitTime",15e3),i(r,"checkTime",400),t.Exposure=r,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["xm-h5-exposure"]={})}(this,(function(t){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function o(t,e){for(var o=0;o<e.length;o++){var i=e[o];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,n(i.key),i)}}function i(t,e,o){return(e=n(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function n(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var i=o.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}!function(){if("object"===("undefined"==typeof window?"undefined":e(window)))if("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)"isIntersecting"in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return this.intersectionRatio>0}});else{var t=function(t){for(var e=window.document,o=r(e);o;)o=r(e=o.ownerDocument);return e}(),o=[],i=null,n=null;a.prototype.THROTTLE_TIMEOUT=100,a.prototype.POLL_INTERVAL=null,a.prototype.USE_MUTATION_OBSERVER=!0,a._setupCrossOriginUpdater=function(){return i||(i=function(t,e){n=t&&e?f(t,e):{top:0,bottom:0,left:0,right:0,width:0,height:0},o.forEach((function(t){t._checkForIntersections()}))}),i},a._resetCrossOriginUpdater=function(){i=null,n=null},a.prototype.observe=function(t){if(!this._observationTargets.some((function(e){return e.element==t}))){if(!t||1!=t.nodeType)throw new Error("target must be an Element");this._registerInstance(),this._observationTargets.push({element:t,entry:null}),this._monitorIntersections(t.ownerDocument),this._checkForIntersections()}},a.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter((function(e){return e.element!=t})),this._unmonitorIntersections(t.ownerDocument),0==this._observationTargets.length&&this._unregisterInstance()},a.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorAllIntersections(),this._unregisterInstance()},a.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},a.prototype._initThresholds=function(t){var e=t||[0];return Array.isArray(e)||(e=[e]),e.sort().filter((function(t,e,o){if("number"!=typeof t||isNaN(t)||t<0||t>1)throw new Error("threshold must be a number between 0 and 1 inclusively");return t!==o[e-1]}))},a.prototype._parseRootMargin=function(t){var e=(t||"0px").split(/\s+/).map((function(t){var e=/^(-?\d*\.?\d+)(px|%)$/.exec(t);if(!e)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(e[1]),unit:e[2]}}));return e[1]=e[1]||e[0],e[2]=e[2]||e[0],e[3]=e[3]||e[1],e},a.prototype._monitorIntersections=function(e){var o=e.defaultView;if(o&&-1==this._monitoringDocuments.indexOf(e)){var i=this._checkForIntersections,n=null,s=null;this.POLL_INTERVAL?n=o.setInterval(i,this.POLL_INTERVAL):(u(o,"resize",i,!0),u(e,"scroll",i,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in o&&(s=new o.MutationObserver(i)).observe(e,{attributes:!0,childList:!0,characterData:!0,subtree:!0})),this._monitoringDocuments.push(e),this._monitoringUnsubscribes.push((function(){var t=e.defaultView;t&&(n&&t.clearInterval(n),c(t,"resize",i,!0)),c(e,"scroll",i,!0),s&&s.disconnect()}));var a=this.root&&(this.root.ownerDocument||this.root)||t;if(e!=a){var h=r(e);h&&this._monitorIntersections(h.ownerDocument)}}},a.prototype._unmonitorIntersections=function(e){var o=this._monitoringDocuments.indexOf(e);if(-1!=o){var i=this.root&&(this.root.ownerDocument||this.root)||t,n=this._observationTargets.some((function(t){var o=t.element.ownerDocument;if(o==e)return!0;for(;o&&o!=i;){var n=r(o);if((o=n&&n.ownerDocument)==e)return!0}return!1}));if(!n){var s=this._monitoringUnsubscribes[o];if(this._monitoringDocuments.splice(o,1),this._monitoringUnsubscribes.splice(o,1),s(),e!=i){var a=r(e);a&&this._unmonitorIntersections(a.ownerDocument)}}}},a.prototype._unmonitorAllIntersections=function(){var t=this._monitoringUnsubscribes.slice(0);this._monitoringDocuments.length=0,this._monitoringUnsubscribes.length=0;for(var e=0;e<t.length;e++)t[e]()},a.prototype._checkForIntersections=function(){if(this.root||!i||n){var t=this._rootIsInDom(),e=t?this._getRootRect():{top:0,bottom:0,left:0,right:0,width:0,height:0};this._observationTargets.forEach((function(o){var n=o.element,r=h(n),a=this._rootContainsTarget(n),u=o.entry,c=t&&a&&this._computeTargetAndRootIntersection(n,r,e),l=null;this._rootContainsTarget(n)?i&&!this.root||(l=e):l={top:0,bottom:0,left:0,right:0,width:0,height:0};var f=o.entry=new s({time:window.performance&&performance.now&&performance.now(),target:n,boundingClientRect:r,rootBounds:l,intersectionRect:c});u?t&&a?this._hasCrossedThreshold(u,f)&&this._queuedEntries.push(f):u&&u.isIntersecting&&this._queuedEntries.push(f):this._queuedEntries.push(f)}),this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)}},a.prototype._computeTargetAndRootIntersection=function(e,o,r){if("none"!=window.getComputedStyle(e).display){for(var s,a,u,c,l,d,m,g,v=o,b=p(e),w=!1;!w&&b;){var y=null,T=1==b.nodeType?window.getComputedStyle(b):{};if("none"==T.display)return null;if(b==this.root||9==b.nodeType)if(w=!0,b==this.root||b==t)i&&!this.root?!n||0==n.width&&0==n.height?(b=null,y=null,v=null):y=n:y=r;else{var _=p(b),I=_&&h(_),E=_&&this._computeTargetAndRootIntersection(_,I,r);I&&E?(b=_,y=f(I,E)):(b=null,v=null)}else{var M=b.ownerDocument;b!=M.body&&b!=M.documentElement&&"visible"!=T.overflow&&(y=h(b))}if(y&&(s=y,a=v,u=void 0,c=void 0,l=void 0,d=void 0,m=void 0,g=void 0,u=Math.max(s.top,a.top),c=Math.min(s.bottom,a.bottom),l=Math.max(s.left,a.left),d=Math.min(s.right,a.right),g=c-u,v=(m=d-l)>=0&&g>=0&&{top:u,bottom:c,left:l,right:d,width:m,height:g}||null),!v)break;b=b&&p(b)}return v}},a.prototype._getRootRect=function(){var e;if(this.root&&!m(this.root))e=h(this.root);else{var o=m(this.root)?this.root:t,i=o.documentElement,n=o.body;e={top:0,left:0,right:i.clientWidth||n.clientWidth,width:i.clientWidth||n.clientWidth,bottom:i.clientHeight||n.clientHeight,height:i.clientHeight||n.clientHeight}}return this._expandRectByRootMargin(e)},a.prototype._expandRectByRootMargin=function(t){var e=this._rootMarginValues.map((function(e,o){return"px"==e.unit?e.value:e.value*(o%2?t.width:t.height)/100})),o={top:t.top-e[0],right:t.right+e[1],bottom:t.bottom+e[2],left:t.left-e[3]};return o.width=o.right-o.left,o.height=o.bottom-o.top,o},a.prototype._hasCrossedThreshold=function(t,e){var o=t&&t.isIntersecting?t.intersectionRatio||0:-1,i=e.isIntersecting?e.intersectionRatio||0:-1;if(o!==i)for(var n=0;n<this.thresholds.length;n++){var r=this.thresholds[n];if(r==o||r==i||r<o!=r<i)return!0}},a.prototype._rootIsInDom=function(){return!this.root||d(t,this.root)},a.prototype._rootContainsTarget=function(e){var o=this.root&&(this.root.ownerDocument||this.root)||t;return d(o,e)&&(!this.root||o==e.ownerDocument)},a.prototype._registerInstance=function(){o.indexOf(this)<0&&o.push(this)},a.prototype._unregisterInstance=function(){var t=o.indexOf(this);-1!=t&&o.splice(t,1)},window.IntersectionObserver=a,window.IntersectionObserverEntry=s}function r(t){try{return t.defaultView&&t.defaultView.frameElement||null}catch(t){return null}}function s(t){this.time=t.time,this.target=t.target,this.rootBounds=l(t.rootBounds),this.boundingClientRect=l(t.boundingClientRect),this.intersectionRect=l(t.intersectionRect||{top:0,bottom:0,left:0,right:0,width:0,height:0}),this.isIntersecting=!!t.intersectionRect;var e=this.boundingClientRect,o=e.width*e.height,i=this.intersectionRect,n=i.width*i.height;this.intersectionRatio=o?Number((n/o).toFixed(4)):this.isIntersecting?1:0}function a(t,e){var o,i,n,r=e||{};if("function"!=typeof t)throw new Error("callback must be a function");if(r.root&&1!=r.root.nodeType&&9!=r.root.nodeType)throw new Error("root must be a Document or Element");this._checkForIntersections=(o=this._checkForIntersections.bind(this),i=this.THROTTLE_TIMEOUT,n=null,function(){n||(n=setTimeout((function(){o(),n=null}),i))}),this._callback=t,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(r.rootMargin),this.thresholds=this._initThresholds(r.threshold),this.root=r.root||null,this.rootMargin=this._rootMarginValues.map((function(t){return t.value+t.unit})).join(" "),this._monitoringDocuments=[],this._monitoringUnsubscribes=[]}function u(t,e,o,i){"function"==typeof t.addEventListener?t.addEventListener(e,o,i||!1):"function"==typeof t.attachEvent&&t.attachEvent("on"+e,o)}function c(t,e,o,i){"function"==typeof t.removeEventListener?t.removeEventListener(e,o,i||!1):"function"==typeof t.detachEvent&&t.detachEvent("on"+e,o)}function h(t){var e;try{e=t.getBoundingClientRect()}catch(t){}return e?(e.width&&e.height||(e={top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:e.right-e.left,height:e.bottom-e.top}),e):{top:0,bottom:0,left:0,right:0,width:0,height:0}}function l(t){return!t||"x"in t?t:{top:t.top,y:t.top,bottom:t.bottom,left:t.left,x:t.left,right:t.right,width:t.width,height:t.height}}function f(t,e){var o=e.top-t.top,i=e.left-t.left;return{top:o,left:i,height:e.height,width:e.width,bottom:o+e.height,right:i+e.width}}function d(t,e){for(var o=e;o;){if(o==t)return!0;o=p(o)}return!1}function p(e){var o=e.parentNode;return 9==e.nodeType&&e!=t?r(e):(o&&o.assignedSlot&&(o=o.assignedSlot.parentNode),o&&11==o.nodeType&&o.host?o.host:o)}function m(t){return t&&9===t.nodeType}}(),window.IntersectionObserver&&(IntersectionObserver.prototype.THROTTLE_TIMEOUT=350);var r=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),i(this,"_observer",void 0),i(this,"dotMap",void 0),i(this,"currentTrickDotArr",void 0),i(this,"currentTrickLogArr",void 0),i(this,"tagTime",void 0),i(this,"tagDateTime",void 0),this.dotMap={},this.currentTrickDotArr=[],this.currentTrickLogArr=[],this.init()}var e,n,r;return e=t,(n=[{key:"init",value:function(){var e=this;this._observer=new IntersectionObserver((function(t){var o=window._xmLog.getCurrentPageName();t.forEach((function(t){e.tagTime||(e.tagTime=t.time,e.tagDateTime=Date.now());var i={id:e.getId(t.target),pageName:o};t.isIntersecting?i.startTime=t.time:i.endTime=t.time,e.currentTrickDotArr.push(i)}))}),{root:null,rootMargin:"0px",threshold:.5}),setInterval((function(){var o="";e.currentTrickDotArr.forEach((function(i){var n=i.id,r=i.startTime,s=i.endTime,a=i.pageName;if(r)e.dotMap[n]?(e.dotMap[n].startTime=r,e.dotMap[n].pageName=a,e.dotMap[n].state="waiting"):e.dotMap[n]={id:n,startTime:r,state:"waiting",endTime:-t.waitTime,pageName:a};else if(e.dotMap[n]&&"waiting"==e.dotMap[n].state){var u=e.dotMap[n];s-u.startTime>t.viewTime&&s-u.endTime>t.waitTime&&(o=e.dotMap[n].pageName,e.currentTrickLogArr.push(n),e.dotMap[n].endTime=s),e.dotMap[n].startTime=0,e.dotMap[n].state="init"}}));var i=Date.now();Object.values(e.dotMap).forEach((function(n){var r=n.id,s=n.startTime,a=n.state,u=n.endTime;if("waiting"===a){var c=i-e.tagDateTime-s+e.tagTime,h=s+c;c>t.viewTime&&h-u>t.waitTime&&(o=e.dotMap[r].pageName,e.currentTrickLogArr.push(r),e.dotMap[r].endTime=h,e.dotMap[r].startTime=0,e.dotMap[r].state="init")}})),e.currentTrickLogArr.length&&e.log(e.currentTrickLogArr,o),e.currentTrickDotArr=[],e.currentTrickLogArr=[]}),t.checkTime)}},{key:"bind",value:function(t){this._observer&&this._observer.observe(t)}},{key:"unbind",value:function(t){var e=this.getId(t);delete this.dotMap[e],this._observer&&this._observer.unobserve(t)}},{key:"getId",value:function(t){var e=t.attributes["data-xm"];return(e?e.value:t.attributes["data-xmv"].value).split(",").map((function(t){return t.split(":")[1]})).join()}},{key:"log",value:function(t,e){var o,i;null===(o=window)||void 0===o||null===(i=o._xmLog)||void 0===i||i.viewLog(t.join(";"),{pageName:e})}}])&&o(e.prototype,n),r&&o(e,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();i(r,"viewTime",1e3),i(r,"waitTime",15e3),i(r,"checkTime",400),t.Exposure=r,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@xm-fe/xm-h5-exposure", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "鲜沐h5曝光埋点", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -12,2 +12,6 @@ ## ⚡️ 简介 | ||
### 0.0.2 | ||
- fix: 修复 pageName 重复调用问题 | ||
### 0.0.1 | ||
@@ -14,0 +18,0 @@ |
34231
78