@ohbug/extension-view 0.1.1 → 0.1.2

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 CHANGED
@@ -1 +1 @@
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;
1
+ "use strict";var M=Object.create;var p=Object.defineProperty;var N=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=N(t,r))||n.enumerable});return e};var X=(e,t,i)=>(i=e!=null?M(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 C=require("@ohbug/utils");var g=class{constructor(t=18e5){o(this,"session",null);o(this,"timeout",18e5);this.session=Date.now(),this.timeout=t}isExpired(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let t=Date.now();return this.session+this.timeout<t}update(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let t=Date.now();return this.session=t,this.session}},L=g;var v=require("@ohbug/utils");function c(e,t){let{client:i}=(0,v.getOhbugObject)(),n=i.createEvent({category:"view",type:"pageView",detail:{initial:t,path:e}});i.notify(n)}function y(e){let{client:t}=(0,v.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()),y(e)):(w.setItem(S,(0,l.default)().toISOString()),y(e))}var f=K;var u=(0,C.getGlobal)(),Q="hidden",O="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===O?(this.initialVisible=!0,c(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===O?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&&(c(u.location.href,!0),f(u.location.href),this.initialVisible=null),i===!1&&t===!0&&r.isExpired()&&(c(u.location.href),f(u.location.href)),t===!1&&r.update()}},T=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,m=t;i.protocol===r.protocol&&i.host===r.host&&(m=r.relative),i.protocol===n.protocol&&i.host===n.host&&(x=n.relative),x!==m&&c(m)}function P(e){return function(i,n,r){return r&&b(E,String(r)),Reflect.apply(e,this,[i,n,r])}}var D,A,h={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(){h.pushState=(0,a.replace)(s==null?void 0:s.history,"pushState",P),h.replaceState=(0,a.replace)(s==null?void 0:s.history,"replaceState",P),h.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 R(){var e;s.history.pushState=h.pushState,s.history.replaceState=h.replaceState,s.onpopstate=h.onpopstate,(e=s==null?void 0:s.removeEventListener)==null||e.call(s,"hashchange",F,!0)}var W=Z;var d=null,$=()=>({name:"OhbugExtensionView",onSetup:()=>{d=T.capturePageVisibility(),W()},onDestroy:()=>{R(),d==null||d.destroy()}}),H=$;var ee=H;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
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};
1
+ var W=Object.defineProperty;var H=(t,e,s)=>e in t?W(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var o=(t,e,s)=>(H(t,typeof e!="symbol"?e+"":e,s),s);import{getGlobal as B}from"@ohbug/utils";var d=class{constructor(e=18e5){o(this,"session",null);o(this,"timeout",18e5);this.session=Date.now(),this.timeout=e}isExpired(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=Date.now();return this.session+this.timeout<e}update(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=Date.now();return this.session=e,this.session}},I=d;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 m(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",M=30;function N(t,e,s=null){let n=JSON.parse(e);return n?l().isAfter(l(n.expiry))?(localStorage.removeItem(t),s):n.value:s}var v={getItem(t){let e=localStorage.getItem(t);return e?N(t,e):null},setItem(t,e){let s=l(),n={value:e,expiry:s.add(M,"day").toISOString()};return localStorage.setItem(t,JSON.stringify(n))},removeItem(t){return localStorage.removeItem(t)}};function j(t){let e=v.getItem(g);e?l(e).isBefore(l(),"day")&&(v.setItem(g,l().toISOString()),m(t)):(v.setItem(g,l().toISOString()),m(t))}var h=j;var a=B(),G="hidden",L="visible",y=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),h(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),h(a.location.href),this.initialVisible=null),s===!1&&e===!0&&r.isExpired()&&(u(a.location.href),h(a.location.href)),e===!1&&r.update()}},O=y;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 C(t){return function(s,n,r){return r&&E(V,String(r)),Reflect.apply(t,this,[s,n,r])}}var T,P,c={pushState:(T=i==null?void 0:i.history)==null?void 0:T.pushState,replaceState:(P=i==null?void 0:i.history)==null?void 0:P.replaceState,onpopstate:i==null?void 0:i.onpopstate};function _(){c.pushState=w(i==null?void 0:i.history,"pushState",C),c.replaceState=w(i==null?void 0:i.history,"replaceState",C),c.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=c.pushState,i.history.replaceState=c.replaceState,i.onpopstate=c.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=O.capturePageVisibility(),F()},onDestroy:()=>{A(),p==null||p.destroy()}}),R=k;var de=R;export{de as default};
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@ohbug/extension-view",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Ohbug extension to collect view data",
5
5
  "license": "MIT",
6
- "author": "chenyueban <jasonchan0527@gmail.com>",
7
6
  "homepage": "https://github.com/ohbug-org/extensions",
8
7
  "bugs": {
9
8
  "url": "https://github.com/ohbug-org/extensions/issues"
@@ -12,27 +11,28 @@
12
11
  "type": "git",
13
12
  "url": "https://github.com/ohbug-org/extensions"
14
13
  },
14
+ "author": "chenyueban <jasonchan0527@gmail.com>",
15
+ "files": [
16
+ "dist"
17
+ ],
15
18
  "main": "dist/index.js",
16
19
  "module": "dist/index.mjs",
17
20
  "types": "dist/index.d.ts",
18
21
  "exports": {
19
22
  ".": {
23
+ "types": "./dist/index.d.ts",
20
24
  "require": "./dist/index.js",
21
- "import": "./dist/index.mjs",
22
- "types": "./dist/index.d.ts"
25
+ "import": "./dist/index.mjs"
23
26
  }
24
27
  },
25
- "files": [
26
- "dist"
27
- ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
28
31
  "dependencies": {
29
32
  "@ohbug/types": "^2.2.1",
30
33
  "@ohbug/utils": "^2.0.8",
31
34
  "dayjs": "^1.11.9"
32
35
  },
33
- "publishConfig": {
34
- "access": "public"
35
- },
36
36
  "scripts": {
37
37
  "prebuild": "rimraf dist",
38
38
  "build": "tsup",