@ohbug/extension-view 0.1.0 → 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 D=Object.create;var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var N=(t,e,i)=>e in t?c(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var R=(t,e)=>{for(var i in e)c(t,i,{get:e[i],enumerable:!0})},E=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of F(e))!M.call(t,s)&&s!==i&&c(t,s,{get:()=>e[s],enumerable:!(n=A(e,s))||n.enumerable});return t};var W=(t,e,i)=>(i=t!=null?D(H(t)):{},E(e||!t||!t.__esModule?c(i,"default",{value:t,enumerable:!0}):i,t)),j=t=>E(c({},"__esModule",{value:!0}),t);var o=(t,e,i)=>(N(t,typeof e!="symbol"?e+"":e,i),i);var Q={};R(Q,{default:()=>K});module.exports=j(Q);var d=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=d;var p=require("@ohbug/utils");function l(t,e){let{client:i}=(0,p.getOhbugObject)(),n=i.createEvent({category:"view",type:"pageView",detail:{initial:e,path:t}});i.notify(n)}function f(t){let{client:e}=(0,p.getOhbugObject)(),i=e.createEvent({category:"view",type:"userView",detail:{path:t}});e.notify(i)}var r=W(require("dayjs"));var g="OhbugExtensionViewUV",B=30;function J(t,e,i=null){let n=JSON.parse(e);return n?(0,r.default)().isAfter((0,r.default)(n.expiry))?(localStorage.removeItem(t),i):n.value:i}var w={getItem(t){let e=localStorage.getItem(t);return e?J(t,e):null},setItem(t,e){let i=(0,r.default)(),n={value:e,expiry:i.add(B,"day").toISOString()};return localStorage.setItem(t,JSON.stringify(n))},removeItem(t){return localStorage.removeItem(t)}};function _(t){let e=w.getItem(g);e?(0,r.default)(e).isBefore((0,r.default)(),"day")&&(w.setItem(g,(0,r.default)().toISOString()),f(t)):(w.setItem(g,(0,r.default)().toISOString()),f(t))}var u=_;var X="hidden",x="visible",m=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),window.addEventListener("visibilitychange",this.handleVisibleChange,!0),this.init(),this.session=new I}static capturePageVisibility(){return new t}init(){this.sendPageLoad||(document.visibilityState===x?(this.initialVisible=!0,l(window.location.href,!0),u(window.location.href),this.sendPageLoad=!0):this.initialVisible=!1)}handleVisibleChange(){this.lastVisible=this.visible,document.visibilityState===x?this.visible=!0:document.visibilityState===X?this.visible=!1:this.visible=null;let{visible:e,lastVisible:i,initialVisible:n,session:s}=this;n===!1&&e===!0&&(l(window.location.href,!0),u(window.location.href),this.initialVisible=null),i===!1&&e===!0&&s.isExpired()&&(l(window.location.href),u(window.location.href)),e===!1&&s.update()}},U=m;var a=require("@ohbug/utils");var S;function y(t,e){var V;let i=(0,a.parseUrl)((V=window==null?void 0:window.location)==null?void 0:V.href),n=(0,a.parseUrl)(t),s=(0,a.parseUrl)(e);n.path||(n=i),S=e;let v=t,h=e;i.protocol===s.protocol&&i.host===s.host&&(h=s.relative),i.protocol===n.protocol&&i.host===n.host&&(v=n.relative),v!==h&&l(h)}function T(t){return function(i,n,s){return s&&y(S,String(s)),t.apply(this,[i,n,s])}}var O,L,b={pushState:(O=window==null?void 0:window.history)==null?void 0:O.pushState,replaceState:(L=window==null?void 0:window.history)==null?void 0:L.replaceState,onpopstate:window==null?void 0:window.onpopstate};function k(){b.pushState=(0,a.replace)(window==null?void 0:window.history,"pushState",T),b.replaceState=(0,a.replace)(window==null?void 0:window.history,"replaceState",T),b.onpopstate=(0,a.replace)(window,"onpopstate",()=>{var e;let t=(e=window==null?void 0:window.location)==null?void 0:e.href;y(S,t)})}function q(t){let{oldURL:e,newURL:i}=t;y(e,i)}function z(){var t;k(),(t=window==null?void 0:window.addEventListener)==null||t.call(window,"hashchange",q,!0)}var P=z;var G=()=>({name:"OhbugExtensionView",onSetup:()=>{U.capturePageVisibility(),P()}}),C=G;var K=C;
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 C=Object.defineProperty;var D=(t,e,i)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var o=(t,e,i)=>(D(t,typeof e!="symbol"?e+"":e,i),i);var u=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}},V=u;import{getOhbugObject as E}from"@ohbug/utils";function a(t,e){let{client:i}=E(),n=i.createEvent({category:"view",type:"pageView",detail:{initial:e,path:t}});i.notify(n)}function h(t){let{client:e}=E(),i=e.createEvent({category:"view",type:"userView",detail:{path:t}});e.notify(i)}import r from"dayjs";var d="OhbugExtensionViewUV",A=30;function F(t,e,i=null){let n=JSON.parse(e);return n?r().isAfter(r(n.expiry))?(localStorage.removeItem(t),i):n.value:i}var p={getItem(t){let e=localStorage.getItem(t);return e?F(t,e):null},setItem(t,e){let i=r(),n={value:e,expiry:i.add(A,"day").toISOString()};return localStorage.setItem(t,JSON.stringify(n))},removeItem(t){return localStorage.removeItem(t)}};function H(t){let e=p.getItem(d);e?r(e).isBefore(r(),"day")&&(p.setItem(d,r().toISOString()),h(t)):(p.setItem(d,r().toISOString()),h(t))}var l=H;var M="hidden",I="visible",f=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),window.addEventListener("visibilitychange",this.handleVisibleChange,!0),this.init(),this.session=new V}static capturePageVisibility(){return new t}init(){this.sendPageLoad||(document.visibilityState===I?(this.initialVisible=!0,a(window.location.href,!0),l(window.location.href),this.sendPageLoad=!0):this.initialVisible=!1)}handleVisibleChange(){this.lastVisible=this.visible,document.visibilityState===I?this.visible=!0:document.visibilityState===M?this.visible=!1:this.visible=null;let{visible:e,lastVisible:i,initialVisible:n,session:s}=this;n===!1&&e===!0&&(a(window.location.href,!0),l(window.location.href),this.initialVisible=null),i===!1&&e===!0&&s.isExpired()&&(a(window.location.href),l(window.location.href)),e===!1&&s.update()}},x=f;import{parseUrl as g,replace as w}from"@ohbug/utils";var b;function S(t,e){var v;let i=g((v=window==null?void 0:window.location)==null?void 0:v.href),n=g(t),s=g(e);n.path||(n=i),b=e;let y=t,c=e;i.protocol===s.protocol&&i.host===s.host&&(c=s.relative),i.protocol===n.protocol&&i.host===n.host&&(y=n.relative),y!==c&&a(c)}function U(t){return function(i,n,s){return s&&S(b,String(s)),t.apply(this,[i,n,s])}}var T,O,m={pushState:(T=window==null?void 0:window.history)==null?void 0:T.pushState,replaceState:(O=window==null?void 0:window.history)==null?void 0:O.replaceState,onpopstate:window==null?void 0:window.onpopstate};function N(){m.pushState=w(window==null?void 0:window.history,"pushState",U),m.replaceState=w(window==null?void 0:window.history,"replaceState",U),m.onpopstate=w(window,"onpopstate",()=>{var e;let t=(e=window==null?void 0:window.location)==null?void 0:e.href;S(b,t)})}function R(t){let{oldURL:e,newURL:i}=t;S(e,i)}function W(){var t;N(),(t=window==null?void 0:window.addEventListener)==null||t.call(window,"hashchange",R,!0)}var L=W;var j=()=>({name:"OhbugExtensionView",onSetup:()=>{x.capturePageVisibility(),L()}}),P=j;var ae=P;export{ae 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.0",
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
- "dependencies": {
29
- "@ohbug/types": "^2.1.1",
30
- "@ohbug/utils": "^2.0.6",
31
- "dayjs": "^1.11.9"
32
- },
33
28
  "publishConfig": {
34
29
  "access": "public"
35
30
  },
31
+ "dependencies": {
32
+ "@ohbug/types": "^2.2.1",
33
+ "@ohbug/utils": "^2.0.8",
34
+ "dayjs": "^1.11.9"
35
+ },
36
36
  "scripts": {
37
37
  "prebuild": "rimraf dist",
38
38
  "build": "tsup",