@ohbug/extension-view 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var N=Object.create;var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var J=(e,t,i)=>t in e?p(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var _=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0})},U=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of j(t))!G.call(e,r)&&r!==i&&p(e,r,{get:()=>t[r],enumerable:!(n=R(t,r))||n.enumerable});return e};var X=(e,t,i)=>(i=e!=null?N(B(e)):{},U(t||!e||!e.__esModule?p(i,"default",{value:e,enumerable:!0}):i,e)),k=e=>U(p({},"__esModule",{value:!0}),e);var o=(e,t,i)=>(J(e,typeof t!="symbol"?t+"":t,i),i);var te={};_(te,{default:()=>ee});module.exports=k(te);var O=require("@ohbug/utils");var g=class{constructor(t=18e5){o(this,"session",null);o(this,"timeout",18e5);this.session=new Date().getTime(),this.timeout=t}isExpired(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let t=new Date().getTime();return this.session+this.timeout<t}update(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let t=new Date().getTime();return this.session=t,this.session}},L=g;var y=require("@ohbug/utils");function h(e,t){let{client:i}=(0,y.getOhbugObject)(),n=i.createEvent({category:"view",type:"pageView",detail:{initial:t,path:e}});i.notify(n)}function v(e){let{client:t}=(0,y.getOhbugObject)(),i=t.createEvent({category:"view",type:"userView",detail:{path:e}});t.notify(i)}var l=X(require("dayjs"));var S="OhbugExtensionViewUV",q=30;function z(e,t,i=null){let n=JSON.parse(t);return n?(0,l.default)().isAfter((0,l.default)(n.expiry))?(localStorage.removeItem(e),i):n.value:i}var w={getItem(e){let t=localStorage.getItem(e);return t?z(e,t):null},setItem(e,t){let i=(0,l.default)(),n={value:t,expiry:i.add(q,"day").toISOString()};return localStorage.setItem(e,JSON.stringify(n))},removeItem(e){return localStorage.removeItem(e)}};function K(e){let t=w.getItem(S);t?(0,l.default)(t).isBefore((0,l.default)(),"day")&&(w.setItem(S,(0,l.default)().toISOString()),v(e)):(w.setItem(S,(0,l.default)().toISOString()),v(e))}var f=K;var u=(0,O.getGlobal)(),Q="hidden",T="visible",V=class e{constructor(){o(this,"visible",null);o(this,"lastVisible",null);o(this,"initialVisible",null);o(this,"sendPageLoad",!1);o(this,"visibleThresholdTimeout",null);o(this,"session");this.handleVisibleChange=this.handleVisibleChange.bind(this),u.addEventListener("visibilitychange",this.handleVisibleChange,!0),this.setup(),this.session=new L}static capturePageVisibility(){return new e}setup(){this.sendPageLoad||(document.visibilityState===T?(this.initialVisible=!0,h(u.location.href,!0),f(u.location.href),this.sendPageLoad=!0):this.initialVisible=!1)}destroy(){u.removeEventListener("visibilitychange",this.handleVisibleChange,!0)}handleVisibleChange(){this.lastVisible=this.visible,document.visibilityState===T?this.visible=!0:document.visibilityState===Q?this.visible=!1:this.visible=null;let{visible:t,lastVisible:i,initialVisible:n,session:r}=this;n===!1&&t===!0&&(h(u.location.href,!0),f(u.location.href),this.initialVisible=null),i===!1&&t===!0&&r.isExpired()&&(h(u.location.href),f(u.location.href)),t===!1&&r.update()}},C=V;var a=require("@ohbug/utils");var s=(0,a.getGlobal)(),E;function b(e,t){var I;let i=(0,a.parseUrl)((I=s==null?void 0:s.location)==null?void 0:I.href),n=(0,a.parseUrl)(e),r=(0,a.parseUrl)(t);n.path||(n=i),E=t;let x=e,d=t;i.protocol===r.protocol&&i.host===r.host&&(d=r.relative),i.protocol===n.protocol&&i.host===n.host&&(x=n.relative),x!==d&&h(d)}function P(e){return function(i,n,r){return r&&b(E,String(r)),e.apply(this,[i,n,r])}}var D,A,c={pushState:(D=s==null?void 0:s.history)==null?void 0:D.pushState,replaceState:(A=s==null?void 0:s.history)==null?void 0:A.replaceState,onpopstate:s==null?void 0:s.onpopstate};function Y(){c.pushState=(0,a.replace)(s==null?void 0:s.history,"pushState",P),c.replaceState=(0,a.replace)(s==null?void 0:s.history,"replaceState",P),c.onpopstate=(0,a.replace)(s,"onpopstate",()=>{var t;let e=(t=s==null?void 0:s.location)==null?void 0:t.href;b(E,e)})}function F(e){let{oldURL:t,newURL:i}=e;b(t,i)}function Z(){var e;Y(),(e=s==null?void 0:s.addEventListener)==null||e.call(s,"hashchange",F,!0)}function W(){var e;s.history.pushState=c.pushState,s.history.replaceState=c.replaceState,s.onpopstate=c.onpopstate,(e=s==null?void 0:s.removeEventListener)==null||e.call(s,"hashchange",F,!0)}var H=Z;var m=null,$=()=>({name:"OhbugExtensionView",onSetup:()=>{m=C.capturePageVisibility(),H()},onDestroy:()=>{W(),m==null||m.destroy()}}),M=$;var ee=M;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var H=Object.defineProperty;var M=(t,e,s)=>e in t?H(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var o=(t,e,s)=>(M(t,typeof e!="symbol"?e+"":e,s),s);import{getGlobal as B}from"@ohbug/utils";var m=class{constructor(e=18e5){o(this,"session",null);o(this,"timeout",18e5);this.session=new Date().getTime(),this.timeout=e}isExpired(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=new Date().getTime();return this.session+this.timeout<e}update(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=new Date().getTime();return this.session=e,this.session}},I=m;import{getOhbugObject as U}from"@ohbug/utils";function u(t,e){let{client:s}=U(),n=s.createEvent({category:"view",type:"pageView",detail:{initial:e,path:t}});s.notify(n)}function d(t){let{client:e}=U(),s=e.createEvent({category:"view",type:"userView",detail:{path:t}});e.notify(s)}import l from"dayjs";var g="OhbugExtensionViewUV",N=30;function R(t,e,s=null){let n=JSON.parse(e);return n?l().isAfter(l(n.expiry))?(localStorage.removeItem(t),s):n.value:s}var y={getItem(t){let e=localStorage.getItem(t);return e?R(t,e):null},setItem(t,e){let s=l(),n={value:e,expiry:s.add(N,"day").toISOString()};return localStorage.setItem(t,JSON.stringify(n))},removeItem(t){return localStorage.removeItem(t)}};function j(t){let e=y.getItem(g);e?l(e).isBefore(l(),"day")&&(y.setItem(g,l().toISOString()),d(t)):(y.setItem(g,l().toISOString()),d(t))}var c=j;var a=B(),G="hidden",L="visible",v=class t{constructor(){o(this,"visible",null);o(this,"lastVisible",null);o(this,"initialVisible",null);o(this,"sendPageLoad",!1);o(this,"visibleThresholdTimeout",null);o(this,"session");this.handleVisibleChange=this.handleVisibleChange.bind(this),a.addEventListener("visibilitychange",this.handleVisibleChange,!0),this.setup(),this.session=new I}static capturePageVisibility(){return new t}setup(){this.sendPageLoad||(document.visibilityState===L?(this.initialVisible=!0,u(a.location.href,!0),c(a.location.href),this.sendPageLoad=!0):this.initialVisible=!1)}destroy(){a.removeEventListener("visibilitychange",this.handleVisibleChange,!0)}handleVisibleChange(){this.lastVisible=this.visible,document.visibilityState===L?this.visible=!0:document.visibilityState===G?this.visible=!1:this.visible=null;let{visible:e,lastVisible:s,initialVisible:n,session:r}=this;n===!1&&e===!0&&(u(a.location.href,!0),c(a.location.href),this.initialVisible=null),s===!1&&e===!0&&r.isExpired()&&(u(a.location.href),c(a.location.href)),e===!1&&r.update()}},T=v;import{getGlobal as J,parseUrl as S,replace as w}from"@ohbug/utils";var i=J(),V;function E(t,e){var x;let s=S((x=i==null?void 0:i.location)==null?void 0:x.href),n=S(t),r=S(e);n.path||(n=s),V=e;let b=t,f=e;s.protocol===r.protocol&&s.host===r.host&&(f=r.relative),s.protocol===n.protocol&&s.host===n.host&&(b=n.relative),b!==f&&u(f)}function O(t){return function(s,n,r){return r&&E(V,String(r)),t.apply(this,[s,n,r])}}var C,P,h={pushState:(C=i==null?void 0:i.history)==null?void 0:C.pushState,replaceState:(P=i==null?void 0:i.history)==null?void 0:P.replaceState,onpopstate:i==null?void 0:i.onpopstate};function _(){h.pushState=w(i==null?void 0:i.history,"pushState",O),h.replaceState=w(i==null?void 0:i.history,"replaceState",O),h.onpopstate=w(i,"onpopstate",()=>{var e;let t=(e=i==null?void 0:i.location)==null?void 0:e.href;E(V,t)})}function D(t){let{oldURL:e,newURL:s}=t;E(e,s)}function X(){var t;_(),(t=i==null?void 0:i.addEventListener)==null||t.call(i,"hashchange",D,!0)}function A(){var t;i.history.pushState=h.pushState,i.history.replaceState=h.replaceState,i.onpopstate=h.onpopstate,(t=i==null?void 0:i.removeEventListener)==null||t.call(i,"hashchange",D,!0)}var F=X;var p=null,k=()=>({name:"OhbugExtensionView",onSetup:()=>{p=T.capturePageVisibility(),F()},onDestroy:()=>{A(),p==null||p.destroy()}}),W=k;var me=W;export{me as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohbug/extension-view",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Ohbug extension to collect view data",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "chenyueban <jasonchan0527@gmail.com>",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ohbug/types": "^2.
|
|
30
|
-
"@ohbug/utils": "^2.0.
|
|
29
|
+
"@ohbug/types": "^2.2.1",
|
|
30
|
+
"@ohbug/utils": "^2.0.8",
|
|
31
31
|
"dayjs": "^1.11.9"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|