anys-web 1.4.1 → 2.0.0

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,2 +1,2 @@
1
- (()=>{var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};(()=>{"use strict";function n(t){return Array.isArray(t)}function r(t,e){return"function"==typeof t&&(!e||!function(t,e){if("function"!=typeof t)return!1;if(t===Symbol)return!1;if(!t.prototype)return!1;const n=t+"",r=n.slice(n.indexOf("{")+1,n.lastIndexOf("}")).trim(),o=0===n.indexOf("class "),i="[native code]"===r,c=o||i;if(e>=4)return c;const u=r.replace(/function.*?\{.*?\}/gm,"").replace(/return/gm,"").replace(/\n+/gm,";").replace(/\s+/gm,"").replace(/;;/gm,";"),s=/^_classCallCheck\(this,/.test(u),a=/^\(.*?_classCallCheck.*?\)\(this,/.test(u),f=/^[0-9a-zA-Z_;!?:]*?\(this,/.test(u),l=c||s||a||f;if(3==e)return l;const p=Object.getOwnPropertyDescriptors(t.prototype),d=!!Object.keys(p).filter((function(t){return"constructor"!==t})).length,h=l||d;if(2==e)return h;const y=0===u.indexOf("this.")||u.indexOf(";this.")>-1||u.indexOf("=this;")>-1,m=h||y;if(1==e)return m;return!0}(t,2))}function o(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:16;const e="0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";let n="";for(let r=0;r<t;r++)n+=e.charAt(Math.floor(Math.random()*e.length));return n}function i(t,e,r){return r?function(){const n=Object.getOwnPropertyDescriptors(t);Object.keys(n).forEach((function(r){const o=n[r],{get:i,set:c,enumerable:u,configurable:s,writable:a}=o;(u||i||c||s&&a)&&e(o,r,t)}))}():function(){if(n(t))t.forEach(e);else{Object.keys(t).forEach((function(n){const r=t[n];e(r,n,t)}))}}()}t.r(e),t.d(e,{create:()=>lt});Symbol("Proxy");const c=["filters","plugins"],u=["filters","plugins","defines"];function s(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function f(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function l(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?f(Object(n),!0).forEach((function(e){p(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):f(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function p(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function d(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},i=Object.keys(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}let h=function(){function t(e){var a=this;this.$events=[],this.$queue=[];const f=(p=this,Object.getPrototypeOf(p).constructor);var p;const h=l(l({},t.defaultOptions),f.defaultOptions||{}),{filters:y=[],plugins:m=[]}=h,v=d(h,c),b=e||{},{filters:g=[],plugins:w=[],defines:O=[]}=b,j=d(b,u),P={},E=[],_={},x=w&&!n(w)&&"object"==typeof w,L=x?Object.values(w):n(w)?w:[],S=x?Object.keys(w).map((function(t){return{key:t,value:w[t]}})):[],A=[].concat(s(m),s(L)),I=function(t){t.forEach((function(t){const e=t.dependencies||[];e.forEach((function(t){A.unshift(t)})),I(e)}))};I(A);const D=A.filter((function(t,e){return e===A.indexOf(t)})),T=[],k={};D.forEach((function(t){const e=S.find((function(e){return e.value===t}))?.key;if(e&&k[e])return void function(e){const n="[Anys]: plugin named '".concat(e,"' has been registered");k[e]instanceof t?console.debug(n,t,k):console.error(n,t,k)}(e);const n=(t.dependencies||[]).map((function(t){return T.find((function(e){return e instanceof t}))})),r=new t(a,n);r.options&&Object.assign(P,r.options()),r.defines&&Object.assign(_,r.defines()),r.filters&&E.push.apply(E,s(r.filters())),T.push(r),e&&(k[e]=r)})),this.$plugins=T,this.plugins=k,this.options=l(l(l({},v),P),j),this.filters=[].concat(s(y),E,s(g));const q=Object.values(this.options).find((function(t){return t&&t instanceof Error}));if(q)throw q;const N=l(l({},_),O);this.definitions=N,this.clientId=N.client?N.client():o(8),this.traceId=N.trace?N.trace():o(8),this.requestId=o(8);const M={};Object.defineProperties(M,function(t,e){if(n(t))return t.map(e);{const n={};return i(t,(function(r,o){n[o]=e(r,o,t)})),n}}(N,(function(t){return{get:r(t)?t:function(){return t},enumerable:!0,configurable:!0}}))),Object.defineProperties(M,{client:{get:function(){return a.clientId},enumerable:!0,configurable:!0},trace:{get:function(){return a.traceId},enumerable:!0,configurable:!0},request:{get:function(){return a.requestId},enumerable:!0,configurable:!0}}),this.$basicLog=M,this.invoke("init"),this.options.autoStart&&this.start()}var e=t.prototype;return e.define=function(t,e){Object.defineProperty(this.$basicLog,t,{get:e,enumerable:!0,configurable:!0})},e.on=function(t,e){this.$events.push([t,e])},e.off=function(t,e){var n=this;this.$events.forEach((function(r,o){r[0]===t&&r[1]===e&&n.$events.splice(o,1)}))},e.emit=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];this.$events.forEach((function(e){e[0]!==t&&"*"!==e[0]||e[1].apply(e,n)}))},e.invoke=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];for(let e=0,o=this.$plugins.length;e<o;e+=1){const o=this.$plugins[e];o[t]&&(r(o[t])&&o[t].apply(o,n))}},e.refreshTraceId=function(){const t=this.traceId;this.traceId=this.definitions.trace?this.definitions.trace():o(8),this.emit("refreshTraceId",{prev:t,next:this.traceId})},e.refreshRequestId=function(){const t=this.requestId;this.requestId=o(8),this.emit("refreshRequestId",{prev:t,next:this.requestId})},e.start=function(){this.invoke("start"),this.emit("start")},e.write=function(t){var e=this;setTimeout((function(){const n=l(l({},e.$basicLog),t),{filters:r}=e;for(let t=0,e=r.length;t<e;t+=1){if(!(0,r[t])(n))return}e.invoke("write",n),e.emit("write",n)}),0)},e.report=function(t){var e=this;let o,i;const c=new Promise((function(t,e){o=t,i=e})),u={message:t,resolve:o,reject:i};this.$queue.push(u),this._reporting=!1;const a=function(){return setTimeout((function(){if(e._reporting)return;e._reporting=!0;const t=e.$queue.shift();if(!t)return;const{message:o,resolve:i,reject:c}=t;e.emit("report",o);const u=[];for(let t=0,n=e.$plugins.length;t<n;t+=1){const n=e.$plugins[t],o={};let i=0;r(n.read)&&(o.read=n.read.bind(n),i=1),r(n.send)&&(o.send=n.send.bind(n),i=1),r(n.clear)&&(o.clear=n.clear.bind(n),i=1),i&&u.push(o)}const f=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];return Promise.resolve().then((function(){return r(t)?t.apply(void 0,n):null}))};(function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return e.reduce((function(t,e){return r(e)?t.then(e):t}),Promise.resolve())})((function(){return Promise.all(u.map((function(t){return f(t.read,o).then((function(e){return t.data=e,e}))})))}),(function(t){const r=[];return t.forEach((function(t){n(t)&&t.length&&r.push.apply(r,s(t))})),e.emit("read",r),r}),(function(t){if(t.length)return e.emit("send",t),Promise.all(u.map((function(e){return f(e.send,e.data,t)}))).then((function(){return t}))}),(function(t){if(t)return e.emit("clear",t),Promise.all(u.map((function(t){return f(t.clear,t.data)})))})).then(i,c).finally((function(){e._reporting=!1,a()}))}),0)};return a(),c},e.stop=function(){this.invoke("stop"),this.emit("stop")},t}();function y(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function m(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?y(Object(n),!0).forEach((function(e){v(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function v(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function b(t,e){if(t.indexOf("?")<0){const n=Object.keys(e).map((function(t){return"".concat(t,"=").concat(e[t])})).join("&"),[r,o]=t.split("#");return r+"?"+n+(o?"#"+o:"")}const[n,r]=t.split("?"),[o,i]=r.split("#"),c=o.split("&").map((function(t){return t.split("=")})).reduce((function(t,e){let[n,r]=e;return m(m({},t),{},{[n]:r})}),{});Object.assign(c,e);return n+"?"+Object.keys(c).map((function(t){return"".concat(t,"=").concat(c[t])})).join("&")+(i?"#"+i:"")}h.defaultOptions={autoStart:!0};let g=function(){function t(t){this.anys=t,this.$effects={}}var e=t.prototype;return e.start=function(){var t=this;if(!this.options)return;const e=this.options(),n=Object.keys(e),r=this.anys.options;n.forEach((function(e){r[e]&&function(e){const n="register".concat(e.replace(e[0],e[0].toUpperCase()));if(t[n]){const r=t[n]();t.$effects[e]=r}}(e)}))},e.stop=function(){var t=this;if(!this.options)return;const e=this.options(),n=Object.keys(e),r=this.anys.options;n.forEach((function(e){const n=t.$effects[e];r[e]&&n&&n(),t.$effects[e]=null}))},t}(),w=function(){function t(){this.$events=[]}var e=t.prototype;return e.on=function(t,e){this.$events.push([t,e])},e.emit=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];this.$events.forEach((function(e){let[r,o]=e;t===r&&o.apply(void 0,n)}))},e.off=function(t,e){var n=this;this.$events.forEach((function(r,o){let[i,c]=r;t===i&&c===e&&n.$events.splice(o,1)}))},t}();function O(t,e){return O=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},O(t,e)}function j(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function P(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?j(Object(n),!0).forEach((function(e){E(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):j(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function E(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}const _=new w;!function(){const t=window.XMLHttpRequest;window.__XMLHttpRequest=t,window.XMLHttpRequest=function(){const e=new t,n={open:e.open,send:e.send},r={name:o(4)},i=function(t){const{name:n,url:o,method:i}=r;let c,u;e.responseType&&"text"!==e.responseType?"json"===e.responseType&&(c=e.response,u="json"):(c=e.responseText.toString(),u="text"),_.emit("xhr",{type:t,time:Date.now(),name:"xhr_".concat(n),url:o,detail:{status:e.status,method:i,responseType:u,response:c||void 0}})},c=function(){4===e.readyState&&(2===Math.floor(e.status/100)?i("xhr.ok"):i("xhr.fail"))};return Object.defineProperty(e,"open",{get:function(){return function(t,o){let i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];const c={method:t,url:o};_.emit("request",c),Object.assign(r,P(P({},c),{},{async:i})),e.onreadystatechange&&(n.onreadystatechange=e.onreadystatechange);const{open:u}=n;for(var s=arguments.length,a=new Array(s>3?s-3:0),f=3;f<s;f++)a[f-3]=arguments[f];return u.call.apply(u,[e,c.method,c.url,i].concat(a))}},configurable:!0}),Object.defineProperty(e,"send",{get:function(){return function(t){const{send:o}=n,{async:i}=r;Object.assign(r,{body:t}),function(){const{name:t,url:e,method:n,async:o,body:i}=r;_.emit("xhr",{type:"xhr.req",time:Date.now(),name:"xhr_".concat(t),url:e,detail:{method:n,async:o,body:i}})}();const u=o.call(e,t);return i||c(),u}},configurable:!0}),e.addEventListener("error",(function(){i("xhr.err")})),e.addEventListener("readystatechange",(function(t){c()})),e}}(),function(){const t=window.fetch;window.__fetch=t,window.fetch=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{method:r,body:i}=n,c=o(4);_.emit("fetch",{type:"fetch.init",time:Date.now(),name:"fetch_".concat(c),url:e,detail:{body:i,method:r}});const u={method:r,url:e};return _.emit("request",u),Promise.resolve().then((function(){return t(u.url,n)})).then((function(t){const{status:n}=t;return 2===Math.floor(n/100)?new Proxy(t,{get:(o,i)=>"json"===i||"text"===i?function(){return t[i]().then((function(t){return _.emit("fetch",{type:"fetch.ok",time:Date.now(),name:"fetch_".concat(c),url:e,detail:{status:n,data:t,method:r}}),t}))}:"function"==typeof t[i]?t[i].bind(t):t[i]}):(_.emit("fetch",{type:"fetch.fail",time:Date.now(),name:"fetch_".concat(c),url:e,detail:{status:n,method:r}}),t)}),(function(t){let n;if(t instanceof Error){const{name:e,message:o}=t;n={method:r,type:e,err:o}}else n={method:r,err:t};_.emit("fetch",{type:"fetch.err",time:Date.now(),name:"fetch_".concat(c),url:e,detail:n})}))}}();let x=function(t){var e,n;function r(){return t.apply(this,arguments)||this}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,O(e,n);var o=r.prototype;return o.options=function(){return{xhr:!0,fetch:!0,ajaxResponse:!0,patchRequestId:!0}},o.registerXhr=function(){var t=this;const e=function(e){t.anys.options.ajaxResponse||"xhr.ok"!==e.type||delete e.detail.response,t.anys.write(e)};return _.on("xhr",e),function(){return _.off("xhr",e)}},o.registerFetch=function(){var t=this;const e=function(e){t.anys.options.ajaxResponse||"fetch.ok"!==e.type||delete e.detail.data,t.anys.write(e)};return _.on("fetch",e),function(){return _.off("fetch",e)}},o.registerPatchRequestId=function(){var t=this;const e=function(e){const{url:n}=e,{traceId:r,requestId:o}=t.anys,i=b(n,{_request_id:r+o});e.url=i};return _.on("request",e),function(){return _.off("request",e)}},r}(g),L=function(){function t(t){this.anys=t}var e=t.prototype;return e.options=function(){return{namespace:new Error("[Anys]: options.namespace is required!")}},e.defines=function(){return{client:this.defineClientId.bind(this),trace:this.defineTraceId.bind(this)}},e.defineClientId=function(){const{namespace:t}=this.anys.options,e="Anys.".concat(t,".clientId");let n=localStorage.getItem(e);return n||(n=o(8),sessionStorage.setItem(e,n)),n},e.defineTraceId=function(){const{namespace:t}=this.anys.options,e="Anys.".concat(t,".traceId"),n=o(8);return sessionStorage.setItem(e,n),n},t}();function S(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document.documentElement;const{nodeName:n,path:r}=t;if(r)return r;if("BODY"===n||"HTML"===n||"HEAD"===n)return n;const o=[];let i=t,c=t.parentNode;const u=function(t){const{nodeName:e,parentNode:n}=t;if(!n)return-1;return[].filter.call(n.childNodes,(function(t){return t.nodeName===e})).indexOf(t)};if("#"===n[0]){const e=u(t);o.push("".concat(n,":").concat(e)),i=c,c=i.parentNode}for(;c&&i!==e;){const{nodeName:t}=i;if("BODY"===t||"HTML"===t||"HEAD"===t)o.push(t);else{const e=u(i);o.push("".concat(t.toLowerCase(),":").concat(e))}i=c,c=i.parentNode}return o.reverse(),o.join("/")}function A(t,e){return A=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},A(t,e)}let I=function(t){var e,n;function r(){return t.apply(this,arguments)||this}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,A(e,n);var o=r.prototype;return o.options=function(){return{input:!0}},o.registerInput=function(){var t=this;const e=function(e){return function(n){const{target:r,type:o,inputType:i,data:c}=n;if("insertCompositionText"===i)return;if("compositionend"===o&&!c)return;const{tagName:u,value:s}=r;if(r.getAttribute("anys-ignore"))return;const a=r.getAttribute("type"),f=e({tagName:u,value:s,type:a,target:r});if(!f)return;const l={type:"input",time:Date.now(),el:S(r),detail:f};t.anys.write(l)}},n=e((function(t){let{tagName:e,value:n,type:r}=t;return"INPUT"===e&&"radio"!==r&&"checkbox"!==r&&"password"!==r?{value:n,type:r}:"INPUT"===e&&"password"===r?{value:"***",type:r}:"TEXTAREA"===e?{value:n,type:"textarea"}:void 0})),r=e((function(t){let{tagName:e,value:n,type:r}=t;return"SELECT"===e?{value:n,type:"select"}:"INPUT"!==e||"radio"!==r&&"checkbox"!==r?void 0:{value:n,type:r}})),o=e((function(t){let{tagName:e,value:n,type:r}=t;return"TEXTAREA"===e?{value:n,type:"textarea"}:"INPUT"===e?{value:n,type:r}:void 0}));return document.addEventListener("input",n,!0),document.addEventListener("compositionend",n,!0),document.addEventListener("change",r,!0),document.addEventListener("paste",o,!0),function(){document.removeEventListener("input",n),document.removeEventListener("compositionend",n),document.removeEventListener("change",r),document.removeEventListener("paste",o)}},r}(g);function D(t,e){return D=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},D(t,e)}let T=function(t){var e,n;function r(){return t.apply(this,arguments)||this}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,D(e,n);var o=r.prototype;return o.options=function(){return{mouse:!("ontouchend"in document),click:!0,mousemove:!1,mousedown:!1,mouseup:!1,wheel:!1,contextmenu:!1}},o.addEventListener=function(t,e){if(!this.anys.options.mouse)return;const n=this.createThrottleListener((function(e){const{innerWidth:n,innerHeight:r}=window,{target:o,button:i,pageX:c,pageY:u}=e;return{type:t,time:Date.now(),detail:{e:S(o),w:n,h:r,x:c,y:u,button:i}}}),e);return document.addEventListener(t,n,!0),function(){return document.removeEventListener(t,n)}},o.registerClick=function(){return this.addEventListener("click")},o.registerMouseup=function(){return this.addEventListener("mouseup")},o.registerMousedown=function(){return this.addEventListener("mousedown")},o.registerContextmenu=function(){return this.addEventListener("contextmenu")},o.registerMousemove=function(){return this.addEventListener("mousemove",100)},o.registerWheel=function(){if(!this.anys.options.mouse)return;const t="wheel",e=this.createThrottleListener((function(e){const{target:n,deltaX:r,deltaY:o,deltaZ:i,deltaMode:c}=e;return{type:t,time:Date.now(),detail:{e:S(n),deltaX:r,deltaY:o,deltaZ:i,mode:c}}}),100);return document.addEventListener(t,e),function(){return document.removeEventListener(t,e)}},o.createThrottleListener=function(t,e){var n=this;let r=0,o=0;return function(i){if(r)return;const c=Date.now();if(e&&o+e>c)return;const u=t(i);requestAnimationFrame((function(){n.anys.write(u),r=0,o=Date.now()})),r=1}},r}(g);function k(t,e){return k=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},k(t,e)}const q={type:"window_activity.enter",time:Date.now()};let N=function(t){var e,n;function r(){return t.apply(this,arguments)||this}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,k(e,n);var o=r.prototype;return o.options=function(){return{activity:!0,deadTimeout:0}},o.init=function(){this.anys.options.activity&&this.anys.write(q)},o.registerActivity=function(){var t=this;const e=function(){if("hidden"===document.visibilityState){const e={type:"window_activity.focusout",time:Date.now()};t.anys.write(e)}else{const e={type:"window_activity.focusin",time:Date.now()};t.anys.write(e)}},n=function(){const e={type:"window_activity.unload",time:Date.now()};t.anys.write(e)};return window.addEventListener("beforeunload",n,!0),document.addEventListener("visibilitychange",e,!0),function(){window.removeEventListener("beforeunload",n),document.removeEventListener("visibilitychange",e)}},o.registerDeadTimeout=function(){var t=this;const{deadTimeout:e}=this.anys.options;if(!e)return;let n;const r=function(){clearTimeout(n),n=setTimeout((function(){const e={type:"window_activity.dead",time:Date.now()};t.anys.write(e)}),e)};return document.addEventListener("keydown",r,!0),document.addEventListener("mousedown",r,!0),document.addEventListener("touchstart",r,!0),document.addEventListener("touchmove",r,!0),document.addEventListener("mousemove",r,!0),document.addEventListener("scroll",r,!0),window.addEventListener("resize",r,!0),function(){document.removeEventListener("keydown",r),document.removeEventListener("mousedown",r),document.removeEventListener("touchstart",r),document.removeEventListener("touchmove",r),document.removeEventListener("mousemove",r),document.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},r}(g);function M(t,e){return M=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},M(t,e)}let $=function(t){var e,n;function r(){return t.apply(this,arguments)||this}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,M(e,n);var o=r.prototype;return o.options=function(){return{url:!0}},o.registerUrl=function(){var t=this;const e=function(){t.recordUrl()};return window.addEventListener("hashchange",e),window.addEventListener("popstate",e),this.recordUrl(),function(){window.removeEventListener("hashchange",e),window.removeEventListener("popstate",e)}},o.recordUrl=function(){const t=window.location.href,e=new URL(t),n=e.pathname.replace(/^([^/])/,"/$1"),r={type:"url",time:Date.now(),url:t,detail:{uri:n+(e.search?"?".concat(e.search):""),path:n,protocol:e.protocol.replace(":",""),host:e.hostname,port:e.port,search:e.search,hash:e.hash.replace("#","")}};this.anys.write(r)},r}(g);function R(t,e){return R=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},R(t,e)}let B=function(t){var e,n;function r(){return t.apply(this,arguments)||this}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,R(e,n);var o=r.prototype;return o.options=function(){const t="ontouchend"in document;return{touch:t,touchstart:t,touchend:t,touchmove:t}},o.addEventListener=function(t){var e=this;if(!this.anys.options.touch)return;let n=0;const r=function(r){if(n)return;const{innerWidth:o,innerHeight:i}=window,{target:c,identifier:u,force:s,pageX:a,pageY:f}=r,l={type:t,time:Date.now(),detail:{e:S(c),width:o,height:i,x:a,y:f,identifier:u,force:s}};requestAnimationFrame((function(){e.anys.write(l),n=0})),n=1};return document.addEventListener(t,r,!0),function(){return document.removeEventListener(t,r)}},o.registerTouchmove=function(){return this.addEventListener("touchmove")},o.registerTouchend=function(){return this.addEventListener("touchend")},o.registerTouchstart=function(){return this.addEventListener("touchstart")},r}(g),U=function(){function t(){this.queue=[],this.status=0}return t.prototype.push=function(t){var e=this;let n,r;const o=new Promise((function(t,e){n=t,r=e})),i={runner:t,resolve:n,reject:r};this.queue.push(i);const c=function(){setTimeout((function(){if(!e.queue.length)return void(e.status=0);const{runner:t,resolve:n,reject:r}=e.queue.shift();t().then(n,r).finally(c)}),0),e.status=1};return this.status||c(),o},t}(),K=function(){function t(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{name:e,version:n=1,stores:r}=t;const o=!e;e||(e="__indb__"),r&&Array.isArray(r)&&r.length||(r=[{name:"__indb__",isKv:!0}]),this.cache={},this.connection=null,this.name=e,this.version=n,this.stores=r;const i=indexedDB.open(e,n);if(i.onupgradeneeded=function(t){const e=t.target.result,n=Array.from(e.objectStoreNames),o=[];r.forEach((function(r){let i=null;if(n.indexOf(r.name)>-1)i=t.target.transaction.objectStore(r.name);else{const t=r.isKv?"key":r.primaryKeyPath,n=!r.isKv&&r.autoIncrement;i=e.createObjectStore(r.name,{keyPath:t,autoIncrement:n})}const c=i.indexNames;c&&c.length&&Array.from(c).forEach((function(t){return i.deleteIndex(t)})),r.indexes&&r.indexes.length&&r.indexes.forEach((function(t){i.createIndex(t.name,t.keyPath||t.name,{unique:t.unique,multiEntry:Array.isArray(t.keyPath)})})),o.push(r.name)})),n&&n.forEach((function(t){-1===o.indexOf(t)&&e.deleteObjectStore(t)}))},i.onblocked=function(t){console.error(H(new Error("indexedDB "+e+" is blocked")))},o)return this.use(e)}var e=t.prototype;return e.connect=function(){var t=this;return new Promise((function(e,n){const r=indexedDB.open(t.name,t.version);r.onerror=function(t){n(H(t))},r.onsuccess=function(t){e(t.target.result)}}))},e.use=function(t){const e=this.stores.find((function(e){return e.name===t}));if(!e)throw new Error("[InDB]: store ".concat(t," is not existing."));if(this.cache[t])return this.cache[t];const n=new C({db:this,store:e});return e.isKv&&Object.defineProperties(n,{key:{value:function(t){return n.keys().then((function(e){return e&&e[t]}))}},getItem:{value:function(t){return n.get(t).then((function(t){return t&&t.value}))}},setItem:{value:function(t,e){return n.put({key:t,value:e})}},removeItem:{value:function(t){return n.delete(t)}}}),this.cache[t]=n,n},e.close=function(){return this.cache=null,this.stores=null,this.connect().then((function(t){t.close()}))},t.deleteDatabase=function(t){return new Promise((function(e,n){const r=indexedDB.deleteDatabase(t);r.onsuccess=function(){e()},r.onerror=function(t){n(t)}}))},t.databases=function(){return indexedDB.databases()},t}();let C=function(){function t(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{store:e,db:n}=t;if("object"!=typeof e||!e.name||"string"!=typeof e.name)throw new Error("[InDBStore]: options.store should be a store config object.");if(!(n instanceof K))throw new Error("[InDBStore]: options.db should be an instanceof InDB.");this.db=n,this.store=e,this.name=e.name,this.primaryKeyPath=e.isKv?"key":e.primaryKeyPath,this._queue=[]}var e=t.prototype;return e.transaction=function(){var t=this;let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const n=function(){const n=t.name,r=e?"readwrite":"readonly",o=t.db.connection;return(o?Promise.resolve(o):t.db.connect()).then((function(e){t.db.connection=e;const o=e.transaction(n,r),i=function(){t.db.connection=null,t._queue.shift()};return o.oncomplete=i,o.onabort=i,o.onerror=i,o}))},r=this._queue[this._queue.length-1],o=r?r.then((function(){return n()})):n();return this._queue.push(o),o},e.objectStore=function(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const e=this.name;return this.transaction(t).then((function(t){return t.objectStore(e)}))},e.cursor=function(t){const{index:e,range:n,direction:r,onTouch:o,onDone:i,onError:c,writable:u=!1}=t;return this.objectStore(u).then((function(t){const u=e?t.index(e):t,s=u.openCursor(n,r);s.onsuccess=function(t){const e=t.target.result;e?o(e,u):i(e,u)},s.onerror=function(t){c(H(t))}}))},e.request=function(t){var e=this;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{writable:r=!1}=n;return new Promise((function(n,o){e.objectStore(r).then((function(e){const r=t(e);r.onsuccess=function(t){const e=t.target.result;n(e)},r.onerror=function(t){o(H(t))}}))}))},e.iterate=function(t){var e=this;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{index:r,range:o,writable:i=!1,direction:c="next"}=n;return new Promise((function(n,u){e.cursor({index:r,range:o,writable:i,direction:c,onTouch:function(e,r){t(e,(function(){return e.continue()}),(function(){r.transaction.commit(),n()}))},onDone:function(){n()},onError:function(t){u(t)}})}))},e.batch=function(t){var e=this;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{writable:r=!0}=n;return this.transaction(r).then((function(n){const r=e.name,o=[],i=n.objectStore(r);return t.forEach((function(t){const e=new Promise((function(e,n){const r=t(i);r.onsuccess=function(t){const n=t.target.result;e(n)},r.onerror=function(t){n(H(t))}}));o.push(e)})),Promise.all(o)}))},e.get=function(t){if(!Array.isArray(t))return this.request((function(e){return e.get(t)}));const e=t.map((function(t){return function(e){return e.get(t)}}));return this.batch(e,{writable:!1})},e.keys=function(){const t=this.primaryKeyPath,e=[];return this.each((function(n){const r=X(n,t);e.push(r)})).then((function(){return e}))},e.all=function(){const t=[];return this.each((function(e){t.push(e)})).then((function(){return t}))},e.count=function(){return this.request((function(t){return t.count()}))},e.each=function(t){return this.iterate((function(e,n){const r=e.value;t(r),n()}))},e.reverse=function(t){return this.iterate((function(e,n){const r=e.value;t(r),n()}),{direction:"prev"})},e.some=function(){var t=this;let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return new Promise((function(r,o){const i=[];let c,u=0,s=n,a=n+e;n<0&&(c="prev",e=Math.min(e,-n),s=-(n+e)||0,a=s+e),t.iterate((function(t,e,n){u<s?(u++,e()):u<a?(i.push(t.value),u++,e()):n()}),{direction:c}).then((function(){n<0&&i.reverse(),r(i)})).catch(o)}))},e.first=function(){return this.some(1).then((function(t){return t[0]}))},e.last=function(){return this.some(1,-1).then((function(t){return t[0]}))},e.find=function(t,e){return this.request((function(n){return n.index(t).get(e)}))},e.query=function(t,e,n){var r=this;const o=function(){switch(n){case">":return IDBKeyRange.lowerBound(e,!0);case">=":return IDBKeyRange.lowerBound(e);case"<":return IDBKeyRange.upperBound(e,!0);case"<=":return IDBKeyRange.upperBound(e);case"%":case"!=":case"in":return;default:return IDBKeyRange.only(e)}}(),i=[];return new Promise((function(c,u){r.cursor({index:t,range:o,onTouch:function(t,r){const o=t.value,c=X(o,r.keyPath);"!="===n?c!==e&&i.push(o):"%"===n?"string"==typeof c&&c.indexOf(e)>-1&&i.push(o):"in"===n?Array.isArray(e)&&e.indexOf(c)>-1&&i.push(o):i.push(o),t.continue()},onDone:function(){c(i)},onError:function(t){u(t)}})}))},e.select=function(){const t=this.store.indexes||[],e={};t.forEach((function(t){const{name:n,keyPath:r}=t;e[n]=r}));const n=function(t,e,n){if(void 0===t)return!1;switch(n){case">":return t>e;case">=":return t>=e;case"<":return t<e;case"<=":return t<=e;case"!=":return t!==e;case"%":return"string"==typeof t&&t.indexOf(e)>-1;case"in":return Array.isArray(e)&&e.indexOf(t)>-1;default:return t===e}},r=function(t,e,r){if(!e.length&&!r.length)return!1;for(let r=0,o=e.length;r<o;r++){const{keyPath:o,value:i,compare:c}=e[r],u=X(t,o);if(!n(u,i,c))return!1}if(!r.length)return!0;for(let e=0,o=r.length;e<o;e++){const{keyPath:o,value:i,compare:c}=r[e],u=X(t,o);if(n(u,i,c))return!0}return!1},o=[];for(var i=arguments.length,c=new Array(i),u=0;u<i;u++)c[u]=arguments[u];c.forEach((function(t){const n=[],r=[];for(let o=0,i=t.length;o<i;o++){const{key:i,value:c,compare:u,optional:s}=t[o],a=e[i]||i;s?n.push({keyPath:a,value:c,compare:u}):r.push({keyPath:a,value:c,compare:u})}o.push([r,n])}));const s=[];return this.each((function(t){(function(t){for(let e=0,n=o.length;e<n;e++){const[n,i]=o[e];if(r(t,n,i))return!0}return!1})(t)&&s.push(t)})).then((function(){return s}))},e.add=function(t,e){if(Array.isArray(t)){const n=t;if(n.length<2)return this.add(t[0],e);const r=n.map((function(t){return function(n){return n.add(t,e)}}));return this.batch(r)}return t?this.request((function(n){return n.add(t,e)}),{writable:!0}):Promise.resolve()},e.put=function(t,e){if(Array.isArray(t)){const n=t;if(n.length<2)return this.put(n[0],e);const r=n.map((function(t){return function(n){return n.put(t,e)}}));return this.batch(r)}return t?this.request((function(n){return n.put(t,e)}),{writable:!0}):Promise.resolve()},e.delete=function(t){if(Array.isArray(t)){const e=t;if(e.length<2)return this.delete(e[0]);const n=e.map((function(t){return function(e){return e.delete(t)}}));return this.batch(n)}return t?this.request((function(e){return e.delete(t)}),{writable:!0}):Promise.resolve()},e.remove=function(t){const e=this.primaryKeyPath;if(Array.isArray(t)){const n=t;if(n.length<2)return this.remove(n[0]);const r=n.map((function(t){const n=X(t,e);return function(t){return t.delete(n)}}));return this.batch(r)}if(!t)return Promise.resolve();const n=X(t,e);return n?this.delete(n):Promise.resolve()},e.clear=function(){return this.request((function(t){return t.clear()}),{writable:!0})},t}();function X(t,e){if(null==e)return;if(Array.isArray(e)){for(let n=0,r=e.length;n<r;n++){const r=X(t,e[n]);if(void 0!==r)return r}return}let n=function(t){return t.toString().split(/\.|\[|\]/).filter((function(t){return!!t}))}(e);if(!n.length)return t;let r=t;for(let t=0,e=n.length;t<e;t++){let e=n[t];if(void 0===r[e])return;r=r[e]}return r}function H(t){const{message:e}=t;return t.message=-1===e.indexOf("[IndexedDB]")?"[IndexedDB]: "+e:e,t}let z=function(){function t(t){this.anys=t}var e=t.prototype;return e.options=function(){return{namespace:new Error("[Anys]: options.namespace is required!"),autoReport:!1,expireTime:1728e5}},e.init=function(){var t=this;const e="anyslogs",n=new K({name:this.anys.options.namespace,version:1,stores:[{name:e,primaryKeyPath:"_id",autoIncrement:!0}]});this.db=n.use(e),this.queue=new U;const{expireTime:r}=this.anys.options;if(r){let e=0;const n=setInterval((function(){t.queue.push((function(){return t.db.some(100,e)})).then((function(o){if(!o.length)return void clearInterval(n);const i=Date.now(),c=[];o.forEach((function(t){const{_id:e,time:n}=t;i-n>r&&c.push(e)})),c.length&&t.queue.push((function(){return t.db.delete(c)})),e+=100,e-=c.length}))}),1e4)}},e.write=function(t){var e=this;this.queue.push((function(){return e.db.add(t)})).then((function(n){e.anys.emit("writeOfflineLog",{id:n,data:t})}))},e.read=function(t){if(t){if(!Array.isArray(t))return;if(t.some((function(t){return!t.key})))return}else t=[{key:"client",value:this.anys.clientId},{key:"trace",value:this.anys.traceId}];return this.select(t)},e.clear=function(t){var e=this;return this.queue.push((function(){return e.db.remove(t)})).catch((function(){}))},e.select=function(t){var e=this;return this.queue.push((function(){return e.db.select(t)}))},e.remove=function(t){var e=this;return this.queue.push((function(){return e.db.delete(t)})).catch((function(){}))},t}();function Y(t){return function(t){if(Array.isArray(t))return F(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return F(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return F(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function F(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function W(t,e){return W=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},W(t,e)}let Z=function(t){var e,n;function r(){return t.apply(this,arguments)||this}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,W(e,n);var o=r.prototype;return o.options=function(){return{mutation:!0}},o.registerMutation=function(){var t=this;const e=this.createObserver((function(e){const n={type:"mutation",time:Date.now(),detail:e};t.anys.write(n)}));return window.addEventListener("load",(function(){e.observe(document,{characterData:!0,attributes:!0,childList:!0,subtree:!0}),t.recordSnapshot(),V(document.documentElement)})),function(){e.disconnect()}},o.recordSnapshot=function(){const t=function(){const{name:t,publicId:e,systemId:n}=document.doctype,r={name:t,publicId:e,systemId:n},o=G(document.documentElement.innerHTML),i={},c=document.querySelector("html");for(let{name:t,value:e}of c.attributes)i[t]=e;const u=function(){const t=document.querySelectorAll("input, textarea, select"),e=[];return Array.from(t).forEach((function(t){const n=S(t),r="password"===t.type?"***":t.value;e.push({el:n,value:r})})),e}();return{doctype:r,attrs:i,html:o,values:u}}(),e=window.location.href,n=new URL(e),r=n.pathname.replace(/^([^/])/,"/$1");this.anys.write({type:"snapshot",time:Date.now(),url:{uri:r+(n.search?"?".concat(n.search):""),path:r,protocol:n.protocol.replace(":",""),host:n.hostname,port:n.port,search:n.search,hash:n.hash.replace("#","")},detail:t})},o.createObserver=function(t){const e=new MutationObserver((function(e){const n=[];Y(e).reverse().forEach((function(t){const{type:e,target:r,attributeName:o,oldValue:i}=t;if(!function(t){if(t.hasAttribute?.("anys-ignore"))return!0;let e=t.parentNode;for(;e;){if(e.hasAttribute?.("anys-ignore"))return!0;e=e.parentNode}return!1}(r)){if("attributes"===e){if(r.getAttribute(o)===i)return;if(n.find((function(t){return t.type===e&&t.target===r&&t.attributeName===o})))return}else if("characterData"===e){const t=r.data;if(t===i)return;if(n.find((function(n){return n.type===e&&n.target===r&&n.target.data===t})))return}n.push(t)}})),n.reverse();const r=[];n.forEach((function(t){const{type:e,target:n,attributeName:o,oldValue:i}=t,c=n.path||S(n),u=function(t){return S(t).replace(c+"/","")};if("attributes"===e){const t=n.getAttribute(o),e=i;r.push({type:"attribute",target:c,name:o,next:t,prev:e})}else if("characterData"===e){const t=n.data,e=i;r.push({type:"text",target:c,next:t,prev:e})}else if("childList"===e){if("TEXTAREA"===n.nodeName)return;const{removedNodes:e,addedNodes:o,previousSibling:i,nextSibling:s}=t,a=[],f=Array.from(e).map((function(t){if(document.body.contains(t))return void a.push({node:t,path:S(t)});const e=t.path?u(t):null,n=i?S(i):null,r=s?S(s):null,o={};return e?o.node=e:(o.before=n,o.after=r),o})).filter(Boolean),l=[],p=Array.from(o).map((function(t){const e=t.nextSibling?u(t.nextSibling):null,n=a.find((function(e){return e.node===t}));if(n)return void l.push({node:n.path,sibling:e});const r="#text"===t.nodeName,o="#comment"===t.nodeName,i=r?t.data:null,c=o?t.data:null;return{text:i,html:r||o?null:G(t.outerHTML),comment:c,sibling:e}})).filter(Boolean);r.push({type:"children",target:c,remove:f,insert:p,move:l}),V(n)}})),t(r)}));return V(document),e},r}(g);function V(t){if(t!==document){const e=S(t);t.path=e}const e=t.childNodes;Array.from(e).forEach((function(t){V(t)}))}function G(t){return t.replace(/<script([^]*?)>([^]*?)<\/script>/gm,"<noscript$1></noscript>").replace(/<noscript([^]*?)>([^]*?)<\/noscript>/gm,"<noscript$1></noscript>").replace(/<link([^]*?)as="script"([^]*?)>/g,"<link$1$2>").replace(/\n\n*\s*\n*\n/gm,"\n")}function J(t,e){return J=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},J(t,e)}let Q=function(t){var e,n;function r(){return t.apply(this,arguments)||this}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,J(e,n);var o=r.prototype;return o.options=function(){return{size:!0}},o.createRecordLog=function(){const{innerWidth:t,innerHeight:e}=window;return{type:"window_size",time:Date.now(),detail:{width:t,height:e}}},o.registerSize=function(){var t=this;let e;const n=function(){clearTimeout(e);const n=t.createRecordLog();e=setTimeout((function(){t.anys.write(n)}),100)};return this.recordSize(),window.addEventListener("resize",n),function(){window.removeEventListener("resize",n)}},o.recordSize=function(){const t=this.createRecordLog();this.anys.write(t)},r}(g);function tt(t,e){return tt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},tt(t,e)}let et=function(t){var e,n;function r(){return t.apply(this,arguments)||this}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,tt(e,n);var o=r.prototype;return o.options=function(){return{scroll:!0}},o.registerScroll=function(){var t=this;let e=0;const n=function(n){if(e)return;const{target:r,bubbles:o}=n;let i;if(o){const{scrollX:t,scrollY:e}=window;i={type:"window_scroll",time:Date.now(),detail:{scrollX:t,scrollY:e}}}else{const{scrollLeft:t,scrollTop:e}=r;i={type:"scroll",time:Date.now(),target:S(r),detail:{scrollLeft:t,scrollTop:e}}}requestAnimationFrame((function(){t.anys.write(i),e=0})),e=1};return window.addEventListener("scroll",n,!0),function(){window.removeEventListener("scroll",n)}},r}(g);const nt=["_id"];function rt(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},i=Object.keys(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}function ot(t,e){return ot=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ot(t,e)}let it=function(t){var e,n;function r(e,n){var r;let[o,i,c,u]=n;return(r=t.call(this,e)||this).offlineStore=o,r.urlMonitor=i,r.windowSizeMonitor=c,r.DOMMutationMonitor=u,r.cache={},r}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,ot(e,n);var o=r.prototype;return o.options=function(){const t="ontouchend"in document;return{touch:t,mouse:!t,click:!1,mousedown:!0,mousemove:!0,mouseup:!0,autoReport:!1,reportUrl:new Error("[Anys]: options.reportUrl is required!"),reportInterval:1e4,reportParams:null}},o.registerAutoReport=function(){var t=this;const{clientId:e}=this.anys,n=function(n){let{prev:r}=n;t.anys.report([{key:"client",value:e},{key:"trace",value:r}]),t.cache={},t.urlMonitor.recordUrl(),t.windowSizeMonitor.recordSize(),t.DOMMutationMonitor.recordSnapshot()};this.anys.on("refreshTraceId",n);const r=setInterval((function(){t.anys.report()}),this.anys.options.reportInterval);let o=0;const i=function(){if(o)return;o=1;const e=Object.keys(t.cache),n=Object.values(t.cache);e.length&&(t.offlineStore.remove(e),navigator.sendBeacon(t.anys.options.reportUrl,JSON.stringify(n)),t.cache={})};window.addEventListener("beforeunload",i),window.addEventListener("pagehide",i),window.addEventListener("unload",i);const c=function(e){let{id:n,data:r}=e;t.cache[n]=r};return this.anys.on("writeOfflineLog",c),function(){t.anys.off("refreshTraceId",n),t.anys.off("writeOfflineLog",c),clearInterval(r),window.removeEventListener("beforeunload",i)}},o.read=function(t){return this.offlineStore.read(t)},o.send=function(t){var e=this;const n=[];let r=0;t.forEach((function(t){n[r]=n[r]||[],n[r].push(t),n[r].length>200&&r++}));const o=n.map((function(t){const n=[],r=[];if(t.forEach((function(t){const{_id:e}=t,o=rt(t,nt);r.push(e),n.push(o)})),!n.length)return;const{reportUrl:o,reportParams:i}=e.anys.options;return function(t,e){return new Promise((function(n,r){const o=new(window.__XMLHttpRequest||window.XMLHttpRequest);o.open("POST",t,!0),o.onreadystatechange=function(){4==o.readyState&&(200==o.status?n(o.responseText):r(new Error("[Anys]: ajax post fail with status ".concat(o.status))))},o.onerror=r,o.send(JSON.stringify(e))}))}(i?b(o,i):o,{data:n}).then((function(){r.forEach((function(t){delete e.cache[t]}))}))}));return Promise.all(o)},o.clear=function(){this.cache={}},r}(g);function ct(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function ut(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ct(Object(n),!0).forEach((function(e){st(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ct(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function st(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function at(t,e){return at=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},at(t,e)}it.dependencies=[z,$,Q,Z,L,x,I,T,N,B,et];let ft=function(t){var e,n;function r(){return t.apply(this,arguments)||this}return n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,at(e,n),r.prototype.auth=function(t){this.options.reportParams=Object.assign(this.options.reportParams||{},t)},r}(h);const lt=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new ft(ut(ut({namespace:"AnysTracer",autoReport:!1},t),{},{plugins:ut(ut({},t.plugins||{}),{},{recorder:it})}))}})();var n=anys="undefined"==typeof anys?{}:anys;for(var r in e)n[r]=e[r];e.__esModule&&Object.defineProperty(n,"__esModule",{value:!0})})();
1
+ !function(){var e={d:function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};!function(){"use strict";function n(e){return Array.isArray(e)}function r(e,t){return"function"==typeof e&&(!t||!function(e,t){if("function"!=typeof e)return!1;if(e===Symbol)return!1;if(!e.prototype)return!1;const n=e+"",r=n.slice(n.indexOf("{")+1,n.lastIndexOf("}")).trim(),s=0===n.indexOf("class "),o="[native code]"===r,i=s||o;if(t>=4)return i;const a=r.replace(/function.*?\{.*?\}/gm,"").replace(/return/gm,"").replace(/\n+/gm,";").replace(/\s+/gm,"").replace(/;;/gm,";"),c=/^_classCallCheck\(this,/.test(a),u=/^\(.*?_classCallCheck.*?\)\(this,/.test(a),h=/^[0-9a-zA-Z_;!?:]*?\(this,/.test(a),d=i||c||u||h;if(3==t)return d;const l=Object.getOwnPropertyDescriptors(e.prototype),p=!!Object.keys(l).filter((e=>"constructor"!==e)).length,m=d||p;if(2==t)return m;const f=0===a.indexOf("this.")||a.indexOf(";this.")>-1||a.indexOf("=this;")>-1,y=m||f;if(1==t)return y;return!0}(e,2))}function s(e=16){const t="0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";let n="";for(let r=0;r<e;r++)n+=t.charAt(Math.floor(Math.random()*t.length));return n}function o(e,t,r){return r?(()=>{const n=Object.getOwnPropertyDescriptors(e);Object.keys(n).forEach((r=>{const s=n[r],{get:o,set:i,enumerable:a,configurable:c,writable:u}=s;(a||o||i||c&&u)&&t(s,r,e)}))})():(()=>{if(n(e))e.forEach(t);else{Object.keys(e).forEach((n=>{const r=e[n];t(r,n,e)}))}})()}e.r(t),e.d(t,{create:function(){return A}});Symbol("Proxy");class i{constructor(e){this.$events=[],this.$queue=[];const t=(a=this,Object.getPrototypeOf(a).constructor);var a;const{filters:c=[],plugins:u=[],...h}={...i.defaultOptions,...t.defaultOptions||{}},{filters:d=[],plugins:l=[],defines:p=[],...m}=e||{},f={},y=[],v={},g=l&&!n(l)&&"object"==typeof l,w=g?D(l):n(l)?l:[],b=g?Object.keys(l).map((e=>({key:e,value:l[e]}))):[],E=[...u,...w],x=e=>{e.forEach((e=>{const t=e.dependencies||[];t.forEach((e=>{E.unshift(e)})),x(t)}))};x(E);const L=E.filter(((e,t)=>t===E.indexOf(e))),I=[],O={};L.forEach((e=>{const t=b.find((t=>t.value===e))?.key;if(t&&O[t])return void(t=>{const n=`plugin named '${t}' has been registered`;O[t]instanceof e?console.debug(n,e,O):console.error(n,e,O)})(t);const n=(e.dependencies||[]).map((e=>I.find((t=>t instanceof e)))),r=new e(this,n);r.options&&T(f,r.options()),r.defines&&T(v,r.defines()),r.filters&&y.push(...r.filters()),I.push(r),t&&(O[t]=r)})),this.$plugins=I,this.plugins=O,this.options={...h,...f,...m},this.filters=[...c,...y,...d];const P=D(this.options).find((e=>e&&e instanceof Error));if(P)throw P;const q={...v,...p};this.definitions=q,this.clientId=q.client?q.client():s(8),this.traceId=q.trace?q.trace():s(8),this.requestId=s(8);const k={};function D(e){return Object.keys(e).map((t=>e[t]))}function T(e,t){return Object.keys(t).forEach((n=>{const r=t[n];e[n]=r})),e}Object.defineProperties(k,function(e,t){if(n(e))return e.map(t);{const n={};return o(e,((r,s)=>{n[s]=t(r,s,e)})),n}}(q,(e=>({get:r(e)?e:()=>e,enumerable:!0,configurable:!0})))),Object.defineProperties(k,{client:{get:()=>this.clientId,enumerable:!0,configurable:!0},trace:{get:()=>this.traceId,enumerable:!0,configurable:!0},request:{get:()=>this.requestId,enumerable:!0,configurable:!0}}),this.$basicLog=k,this.invoke("init"),this.options.autoStart&&this.start()}define(e,t){Object.defineProperty(this.$basicLog,e,{get:t,enumerable:!0,configurable:!0})}on(e,t){this.$events.push([e,t])}off(e,t){this.$events.forEach(((n,r)=>{n[0]===e&&n[1]===t&&this.$events.splice(r,1)}))}emit(e,...t){this.$events.forEach((n=>{n[0]!==e&&"*"!==n[0]||n[1](...t)}))}invoke(e,...t){for(let n=0,s=this.$plugins.length;n<s;n+=1){const s=this.$plugins[n];s[e]&&(r(s[e])&&s[e](...t))}}refreshTraceId(){const e=this.traceId;this.traceId=this.definitions.trace?this.definitions.trace():s(8),this.emit("refreshTraceId",{prev:e,next:this.traceId})}refreshRequestId(){const e=this.requestId;this.requestId=s(8),this.emit("refreshRequestId",{prev:e,next:this.requestId})}start(){this.invoke("start"),this.emit("start")}write(e){setTimeout((()=>{const t={...this.$basicLog,...e},{filters:n}=this;for(let e=0,r=n.length;e<r;e+=1){if(!(0,n[e])(t))return}this.invoke("write",t),this.emit("write",t)}),0)}report(e){let t,s;const o=new Promise(((e,n)=>{t=e,s=n})),i={message:e,resolve:t,reject:s};this.$queue.push(i),this._reporting=!1;const a=()=>setTimeout((()=>{if(this._reporting)return;this._reporting=!0;const e=this.$queue.shift();if(!e)return;const{message:t,resolve:s,reject:o}=e;this.emit("report",t);const i=[];for(let e=0,t=this.$plugins.length;e<t;e+=1){const t=this.$plugins[e],n={};let s=0;r(t.read)&&(n.read=t.read.bind(t),s=1),r(t.send)&&(n.send=t.send.bind(t),s=1),r(t.clear)&&(n.clear=t.clear.bind(t),s=1),s&&i.push(n)}const c=(e,...t)=>Promise.resolve().then((()=>r(e)?e(...t):null));((...e)=>e.reduce(((e,t)=>r(t)?e.then(t):e),Promise.resolve()))((()=>Promise.all(i.map((e=>c(e.read,t).then((t=>(e.data=t,t))))))),(e=>{const t=[];return e.forEach((e=>{n(e)&&e.length&&t.push(...e)})),this.emit("read",t),t}),(e=>{if(e.length)return this.emit("send",e),Promise.all(i.map((t=>c(t.send,t.data,e)))).then((()=>e))}),(e=>{if(e)return this.emit("clear",e),Promise.all(i.map((e=>c(e.clear,e.data))))})).then(s,o).finally((()=>{this._reporting=!1,a()}))}),0);return a(),o}stop(){this.invoke("stop"),this.emit("stop")}static defaultOptions={autoStart:!0}}class a{constructor(e){this.anys=e,this.$effects={}}start(){if(!this.options)return;const e=this.options(),t=Object.keys(e),n=e=>{const t=`register${e.replace(e[0],e[0].toUpperCase())}`;if(this[t]){const n=this[t]();this.$effects[e]=n}},r=this.anys.options;t.forEach((e=>{r[e]&&n(e)}))}stop(){if(!this.options)return;const e=this.options(),t=Object.keys(e),n=this.anys.options;t.forEach((e=>{const t=this.$effects[e];n[e]&&t&&t(),this.$effects[e]=null}))}}function c(e,t){if(e.indexOf("?")<0){const n=Object.keys(t).map((e=>`${e}=${t[e]}`)).join("&"),[r,s]=e.split("#");return r+"?"+n+(s?"#"+s:"")}const[n,r]=e.split("?"),[s,o]=r.split("#"),i=s.split("&").map((e=>e.split("="))).reduce(((e,[t,n])=>({...e,[t]:n})),{});Object.assign(i,t);return n+"?"+Object.keys(i).map((e=>`${e}=${i[e]}`)).join("&")+(o?"#"+o:"")}const u=new class{constructor(){this.$events=[]}on(e,t){this.$events.push([e,t])}emit(e,...t){this.$events.forEach((([n,r])=>{e===n&&r(...t)}))}off(e,t){this.$events.forEach((([n,r],s)=>{e===n&&r===t&&this.$events.splice(s,1)}))}};!function(){const e=window.XMLHttpRequest;window.__XMLHttpRequest=e,window.XMLHttpRequest=function(){const t=new e,n={open:t.open,send:t.send},r={name:s(4)},o=e=>{const{name:n,url:s,method:o}=r;let i,a;t.responseType&&"text"!==t.responseType?"json"===t.responseType&&(i=t.response,a="json"):(i=t.responseText.toString(),a="text"),u.emit("xhr",{type:e,time:Date.now(),name:`xhr_${n}`,url:s,detail:{status:t.status,method:o,responseType:a,response:i||void 0}})},i=()=>{4===t.readyState&&(2===Math.floor(t.status/100)?o("xhr.ok"):o("xhr.fail"))};return Object.defineProperty(t,"open",{get:()=>(e,s,o=!0,...i)=>{const a={method:e,url:s};u.emit("request",a),Object.assign(r,{...a,async:o}),t.onreadystatechange&&(n.onreadystatechange=t.onreadystatechange);const{open:c}=n;return c.call(t,a.method,a.url,o,...i)},configurable:!0}),Object.defineProperty(t,"send",{get:()=>e=>{const{send:s}=n,{async:o}=r;Object.assign(r,{body:e}),(()=>{const{name:e,url:t,method:n,async:s,body:o}=r;u.emit("xhr",{type:"xhr.req",time:Date.now(),name:`xhr_${e}`,url:t,detail:{method:n,async:s,body:o}})})();const a=s.call(t,e);return o||i(),a},configurable:!0}),t.addEventListener("error",(()=>{o("xhr.err")})),t.addEventListener("readystatechange",(e=>{i()})),t}}(),function(){const e=window.fetch;window.__fetch=e,window.fetch=function(t,n={}){const{method:r,body:o}=n,i=s(4);u.emit("fetch",{type:"fetch.init",time:Date.now(),name:`fetch_${i}`,url:t,detail:{body:o,method:r}});const a={method:r,url:t};return u.emit("request",a),Promise.resolve().then((()=>e(a.url,n))).then((e=>{const{status:n}=e;return 2===Math.floor(n/100)?new Proxy(e,{get(s,o){return"json"===o||"text"===o?()=>e[o]().then((e=>(u.emit("fetch",{type:"fetch.ok",time:Date.now(),name:`fetch_${i}`,url:t,detail:{status:n,data:e,method:r}}),e))):"function"==typeof e[o]?e[o].bind(e):e[o]}}):(u.emit("fetch",{type:"fetch.fail",time:Date.now(),name:`fetch_${i}`,url:t,detail:{status:n,method:r}}),e)}),(e=>{let n;if(e instanceof Error){const{name:t,message:s}=e;n={method:r,type:t,err:s}}else n={method:r,err:e};u.emit("fetch",{type:"fetch.err",time:Date.now(),name:`fetch_${i}`,url:t,detail:n})}))}}();class h extends a{options(){return{xhr:!0,fetch:!0,ajaxResponse:!0,patchRequestId:!0}}registerXhr(){const e=e=>{this.anys.options.ajaxResponse||"xhr.ok"!==e.type||delete e.detail.response,this.anys.write(e)};return u.on("xhr",e),()=>u.off("xhr",e)}registerFetch(){const e=e=>{this.anys.options.ajaxResponse||"fetch.ok"!==e.type||delete e.detail.data,this.anys.write(e)};return u.on("fetch",e),()=>u.off("fetch",e)}registerPatchRequestId(){const e=e=>{const{url:t}=e,{traceId:n,requestId:r}=this.anys,s=c(t,{_request_id:n+r});e.url=s};return u.on("request",e),()=>u.off("request",e)}}class d{constructor(e){this.anys=e}options(){return{namespace:new Error("options.namespace is required!")}}defines(){return{client:this.defineClientId.bind(this),trace:this.defineTraceId.bind(this)}}defineClientId(){const{namespace:e}=this.anys.options,t=`Anys.${e}.clientId`;let n=localStorage.getItem(t);return n||(n=s(8),sessionStorage.setItem(t,n)),n}defineTraceId(){const{namespace:e}=this.anys.options,t=`Anys.${e}.traceId`,n=s(8);return sessionStorage.setItem(t,n),n}}function l(e,t=document.documentElement){const{nodeName:n,path:r}=e;if(r)return r;if("BODY"===n||"HTML"===n||"HEAD"===n)return n;const s=[];let o=e,i=e.parentNode;const a=e=>{const{nodeName:t,parentNode:n}=e;if(!n)return-1;return[].filter.call(n.childNodes,(e=>e.nodeName===t)).indexOf(e)};if("#"===n[0]){const t=a(e);s.push(`${n}:${t}`),o=i,i=o.parentNode}for(;i&&o!==t;){const{nodeName:e}=o;if("BODY"===e||"HTML"===e||"HEAD"===e)s.push(e);else{const t=a(o);s.push(`${e.toLowerCase()}:${t}`)}o=i,i=o.parentNode}return s.reverse(),s.join("/")}class p extends a{options(){return{input:!0}}registerInput(){const e=e=>t=>{const{target:n,type:r,inputType:s,data:o}=t;if("insertCompositionText"===s)return;if("compositionend"===r&&!o)return;const{tagName:i,value:a}=n;if(n.getAttribute("anys-ignore"))return;const c=n.getAttribute("type"),u=e({tagName:i,value:a,type:c,target:n});if(!u)return;const h={type:"input",time:Date.now(),el:l(n),detail:u};this.anys.write(h)},t=e((({tagName:e,value:t,type:n})=>"INPUT"===e&&"radio"!==n&&"checkbox"!==n&&"password"!==n?{value:t,type:n}:"INPUT"===e&&"password"===n?{value:"***",type:n}:"TEXTAREA"===e?{value:t,type:"textarea"}:void 0)),n=e((({tagName:e,value:t,type:n})=>"SELECT"===e?{value:t,type:"select"}:"INPUT"!==e||"radio"!==n&&"checkbox"!==n?void 0:{value:t,type:n})),r=e((({tagName:e,value:t,type:n})=>"TEXTAREA"===e?{value:t,type:"textarea"}:"INPUT"===e?{value:t,type:n}:void 0));return document.addEventListener("input",t,!0),document.addEventListener("compositionend",t,!0),document.addEventListener("change",n,!0),document.addEventListener("paste",r,!0),()=>{document.removeEventListener("input",t),document.removeEventListener("compositionend",t),document.removeEventListener("change",n),document.removeEventListener("paste",r)}}}class m extends a{options(){return{mouse:!("ontouchend"in document),click:!0,mousemove:!1,mousedown:!1,mouseup:!1,wheel:!1,contextmenu:!1}}addEventListener(e,t){if(!this.anys.options.mouse)return;const n=this.createThrottleListener((t=>{const{innerWidth:n,innerHeight:r}=window,{target:s,button:o,pageX:i,pageY:a}=t;return{type:e,time:Date.now(),detail:{e:l(s),w:n,h:r,x:i,y:a,button:o}}}),t);return document.addEventListener(e,n,!0),()=>document.removeEventListener(e,n)}registerClick(){return this.addEventListener("click")}registerMouseup(){return this.addEventListener("mouseup")}registerMousedown(){return this.addEventListener("mousedown")}registerContextmenu(){return this.addEventListener("contextmenu")}registerMousemove(){return this.addEventListener("mousemove",100)}registerWheel(){if(!this.anys.options.mouse)return;const e="wheel",t=this.createThrottleListener((t=>{const{target:n,deltaX:r,deltaY:s,deltaZ:o,deltaMode:i}=t;return{type:e,time:Date.now(),detail:{e:l(n),deltaX:r,deltaY:s,deltaZ:o,mode:i}}}),100);return document.addEventListener(e,t),()=>document.removeEventListener(e,t)}createThrottleListener(e,t){let n=0,r=0;return s=>{if(n)return;const o=Date.now();if(t&&r+t>o)return;const i=e(s);requestAnimationFrame((()=>{this.anys.write(i),n=0,r=Date.now()})),n=1}}}const f={type:"window_activity.enter",time:Date.now()};class y extends a{options(){return{activity:!0,deadTimeout:0}}init(){this.anys.options.activity&&this.anys.write(f)}registerActivity(){const e=()=>{if("hidden"===document.visibilityState){const e={type:"window_activity.focusout",time:Date.now()};this.anys.write(e)}else{const e={type:"window_activity.focusin",time:Date.now()};this.anys.write(e)}},t=()=>{const e={type:"window_activity.unload",time:Date.now()};this.anys.write(e)};return window.addEventListener("beforeunload",t,!0),document.addEventListener("visibilitychange",e,!0),()=>{window.removeEventListener("beforeunload",t),document.removeEventListener("visibilitychange",e)}}registerDeadTimeout(){const{deadTimeout:e}=this.anys.options;if(!e)return;let t;const n=()=>{clearTimeout(t),t=setTimeout((()=>{const e={type:"window_activity.dead",time:Date.now()};this.anys.write(e)}),e)};return document.addEventListener("keydown",n,!0),document.addEventListener("mousedown",n,!0),document.addEventListener("touchstart",n,!0),document.addEventListener("touchmove",n,!0),document.addEventListener("mousemove",n,!0),document.addEventListener("scroll",n,!0),window.addEventListener("resize",n,!0),()=>{document.removeEventListener("keydown",n),document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n),document.removeEventListener("touchmove",n),document.removeEventListener("mousemove",n),document.removeEventListener("scroll",n),window.removeEventListener("resize",n)}}}class v extends a{options(){return{url:!0}}registerUrl(){const e=()=>{this.recordUrl()};return window.addEventListener("hashchange",e),window.addEventListener("popstate",e),this.recordUrl(),()=>{window.removeEventListener("hashchange",e),window.removeEventListener("popstate",e)}}recordUrl(){const e=window.location.href,t=new URL(e),n=t.pathname.replace(/^([^/])/,"/$1"),r={type:"url",time:Date.now(),url:e,detail:{uri:n+(t.search?`?${t.search}`:""),path:n,protocol:t.protocol.replace(":",""),host:t.hostname,port:t.port,search:t.search,hash:t.hash.replace("#","")}};this.anys.write(r)}}class g extends a{options(){const e="ontouchend"in document;return{touch:e,touchstart:e,touchend:e,touchmove:e}}addEventListener(e){if(!this.anys.options.touch)return;let t=0;const n=n=>{if(t)return;const{innerWidth:r,innerHeight:s}=window,{target:o,identifier:i,force:a,pageX:c,pageY:u}=n,h={type:e,time:Date.now(),detail:{e:l(o),width:r,height:s,x:c,y:u,identifier:i,force:a}};requestAnimationFrame((()=>{this.anys.write(h),t=0})),t=1};return document.addEventListener(e,n,!0),()=>document.removeEventListener(e,n)}registerTouchmove(){return this.addEventListener("touchmove")}registerTouchend(){return this.addEventListener("touchend")}registerTouchstart(){return this.addEventListener("touchstart")}}class w{constructor(){this.queue=[],this.status=0}push(e){let t,n;const r=new Promise(((e,r)=>{t=e,n=r})),s={runner:e,resolve:t,reject:n};this.queue.push(s);const o=()=>{setTimeout((()=>{if(!this.queue.length)return void(this.status=0);const{runner:e,resolve:t,reject:n}=this.queue.shift();e().then(t,n).finally(o)}),0),this.status=1};return this.status||o(),r}}class b{constructor(e={}){let{name:t,version:n=1,stores:r}=e;const s=!t;t||(t="__indb__"),r&&Array.isArray(r)&&r.length||(r=[{name:"__indb__",isKv:!0}]),this.cache={},this.connection=null,this.name=t,this.version=n,this.stores=r;const o=indexedDB.open(t,n);if(o.onupgradeneeded=e=>{const t=e.target.result,n=Array.from(t.objectStoreNames),s=[];r.forEach((r=>{let o=null;if(n.indexOf(r.name)>-1)o=e.target.transaction.objectStore(r.name);else{const e=r.isKv?"key":r.primaryKeyPath,n=!r.isKv&&r.autoIncrement;o=t.createObjectStore(r.name,{keyPath:e,autoIncrement:n})}const i=o.indexNames;i&&i.length&&Array.from(i).forEach((e=>o.deleteIndex(e))),r.indexes&&r.indexes.length&&r.indexes.forEach((e=>{o.createIndex(e.name,e.keyPath||e.name,{unique:e.unique,multiEntry:Array.isArray(e.keyPath)})})),s.push(r.name)})),n&&n.forEach((e=>{-1===s.indexOf(e)&&t.deleteObjectStore(e)}))},o.onblocked=e=>{console.error(L(new Error("indexedDB "+t+" is blocked")))},s)return this.use(t)}connect(){return new Promise(((e,t)=>{const n=indexedDB.open(this.name,this.version);n.onerror=e=>{t(L(e))},n.onsuccess=t=>{e(t.target.result)}}))}use(e){const t=this.stores.find((t=>t.name===e));if(!t)throw new Error(`[InDB]: store ${e} is not existing.`);if(this.cache[e])return this.cache[e];const n=new E({db:this,store:t});return t.isKv&&Object.defineProperties(n,{key:{value:e=>n.keys().then((t=>t&&t[e]))},getItem:{value:e=>n.get(e).then((e=>e&&e.value))},setItem:{value:(e,t)=>n.put({key:e,value:t})},removeItem:{value:e=>n.delete(e)}}),this.cache[e]=n,n}close(){return this.cache=null,this.stores=null,this.connect().then((e=>{e.close()}))}static deleteDatabase(e){return new Promise(((t,n)=>{const r=indexedDB.deleteDatabase(e);r.onsuccess=()=>{t()},r.onerror=e=>{n(e)}}))}static databases(){return indexedDB.databases()}}class E{constructor(e={}){const{store:t,db:n}=e;if("object"!=typeof t||!t.name||"string"!=typeof t.name)throw new Error("[InDBStore]: options.store should be a store config object.");if(!(n instanceof b))throw new Error("[InDBStore]: options.db should be an instanceof InDB.");this.db=n,this.store=t,this.name=t.name,this.primaryKeyPath=t.isKv?"key":t.primaryKeyPath,this._queue=[]}transaction(e=!1){const t=()=>{const t=this.name,n=e?"readwrite":"readonly",r=this.db.connection;return(r?Promise.resolve(r):this.db.connect()).then((e=>{this.db.connection=e;const r=e.transaction(t,n),s=()=>{this.db.connection=null,this._queue.shift()};return r.oncomplete=s,r.onabort=s,r.onerror=s,r}))},n=this._queue[this._queue.length-1],r=n?n.then((()=>t())):t();return this._queue.push(r),r}objectStore(e=!1){const t=this.name;return this.transaction(e).then((e=>e.objectStore(t)))}cursor(e){const{index:t,range:n,direction:r,onTouch:s,onDone:o,onError:i,writable:a=!1}=e;return this.objectStore(a).then((e=>{const a=t?e.index(t):e,c=a.openCursor(n,r);c.onsuccess=e=>{const t=e.target.result;t?s(t,a):o(t,a)},c.onerror=e=>{i(L(e))}}))}request(e,t={}){const{writable:n=!1}=t;return new Promise(((t,r)=>{this.objectStore(n).then((n=>{const s=e(n);s.onsuccess=e=>{const n=e.target.result;t(n)},s.onerror=e=>{r(L(e))}}))}))}iterate(e,t={}){const{index:n,range:r,writable:s=!1,direction:o="next"}=t;return new Promise(((t,i)=>{this.cursor({index:n,range:r,writable:s,direction:o,onTouch:(n,r)=>{e(n,(()=>n.continue()),(()=>{r.transaction.commit(),t()}))},onDone:()=>{t()},onError:e=>{i(e)}})}))}batch(e,t={}){const{writable:n=!0}=t;return this.transaction(n).then((t=>{const n=this.name,r=[],s=t.objectStore(n);return e.forEach((e=>{const t=new Promise(((t,n)=>{const r=e(s);r.onsuccess=e=>{const n=e.target.result;t(n)},r.onerror=e=>{n(L(e))}}));r.push(t)})),Promise.all(r)}))}get(e){if(!Array.isArray(e))return this.request((t=>t.get(e)));const t=e.map((e=>t=>t.get(e)));return this.batch(t,{writable:!1})}keys(){const e=this.primaryKeyPath,t=[];return this.each((n=>{const r=x(n,e);t.push(r)})).then((()=>t))}all(){const e=[];return this.each((t=>{e.push(t)})).then((()=>e))}count(){return this.request((e=>e.count()))}each(e){return this.iterate(((t,n)=>{const r=t.value;e(r),n()}))}reverse(e){return this.iterate(((t,n)=>{const r=t.value;e(r),n()}),{direction:"prev"})}some(e=10,t=0){return new Promise(((n,r)=>{const s=[];let o,i=0,a=t,c=t+e;t<0&&(o="prev",e=Math.min(e,-t),a=-(t+e)||0,c=a+e),this.iterate(((e,t,n)=>{i<a?(i++,t()):i<c?(s.push(e.value),i++,t()):n()}),{direction:o}).then((()=>{t<0&&s.reverse(),n(s)})).catch(r)}))}first(){return this.some(1).then((e=>e[0]))}last(){return this.some(1,-1).then((e=>e[0]))}find(e,t){return this.request((n=>n.index(e).get(t)))}query(e,t,n){const r=function(){switch(n){case">":return IDBKeyRange.lowerBound(t,!0);case">=":return IDBKeyRange.lowerBound(t);case"<":return IDBKeyRange.upperBound(t,!0);case"<=":return IDBKeyRange.upperBound(t);case"%":case"!=":case"in":return;default:return IDBKeyRange.only(t)}}(),s=[];return new Promise(((o,i)=>{this.cursor({index:e,range:r,onTouch:(e,r)=>{const o=e.value,i=x(o,r.keyPath);"!="===n?i!==t&&s.push(o):"%"===n?"string"==typeof i&&i.indexOf(t)>-1&&s.push(o):"in"===n?Array.isArray(t)&&t.indexOf(i)>-1&&s.push(o):s.push(o),e.continue()},onDone:()=>{o(s)},onError:e=>{i(e)}})}))}select(...e){const t=this.store.indexes||[],n={};t.forEach((e=>{const{name:t,keyPath:r}=e;n[t]=r}));const r=function(e,t,n){if(void 0===e)return!1;switch(n){case">":return e>t;case">=":return e>=t;case"<":return e<t;case"<=":return e<=t;case"!=":return e!==t;case"%":return"string"==typeof e&&e.indexOf(t)>-1;case"in":return Array.isArray(t)&&t.indexOf(e)>-1;default:return e===t}},s=function(e,t,n){if(!t.length&&!n.length)return!1;for(let n=0,s=t.length;n<s;n++){const{keyPath:s,value:o,compare:i}=t[n],a=x(e,s);if(!r(a,o,i))return!1}if(!n.length)return!0;for(let t=0,s=n.length;t<s;t++){const{keyPath:s,value:o,compare:i}=n[t],a=x(e,s);if(r(a,o,i))return!0}return!1},o=[];e.forEach((e=>{const t=[],r=[];for(let s=0,o=e.length;s<o;s++){const{key:o,value:i,compare:a,optional:c}=e[s],u=n[o]||o;c?t.push({keyPath:u,value:i,compare:a}):r.push({keyPath:u,value:i,compare:a})}o.push([r,t])}));const i=[];return this.each((e=>{(e=>{for(let t=0,n=o.length;t<n;t++){const[n,r]=o[t];if(s(e,n,r))return!0}return!1})(e)&&i.push(e)})).then((()=>i))}add(e,t){if(Array.isArray(e)){const n=e;if(n.length<2)return this.add(e[0],t);const r=n.map((e=>n=>n.add(e,t)));return this.batch(r)}return e?this.request((n=>n.add(e,t)),{writable:!0}):Promise.resolve()}put(e,t){if(Array.isArray(e)){const n=e;if(n.length<2)return this.put(n[0],t);const r=n.map((e=>n=>n.put(e,t)));return this.batch(r)}return e?this.request((n=>n.put(e,t)),{writable:!0}):Promise.resolve()}delete(e){if(Array.isArray(e)){const t=e;if(t.length<2)return this.delete(t[0]);const n=t.map((e=>t=>t.delete(e)));return this.batch(n)}return e?this.request((t=>t.delete(e)),{writable:!0}):Promise.resolve()}remove(e){const t=this.primaryKeyPath;if(Array.isArray(e)){const n=e;if(n.length<2)return this.remove(n[0]);const r=n.map((e=>{const n=x(e,t);return e=>e.delete(n)}));return this.batch(r)}if(!e)return Promise.resolve();const n=x(e,t);return n?this.delete(n):Promise.resolve()}clear(){return this.request((e=>e.clear()),{writable:!0})}}function x(e,t){if(null==t)return;if(Array.isArray(t)){for(let n=0,r=t.length;n<r;n++){const r=x(e,t[n]);if(void 0!==r)return r}return}let n=function(e){return e.toString().split(/\.|\[|\]/).filter((e=>!!e))}(t);if(!n.length)return e;let r=e;for(let e=0,t=n.length;e<t;e++){let t=n[e];if(void 0===r[t])return;r=r[t]}return r}function L(e){const{message:t}=e;return e.message=-1===t.indexOf("[IndexedDB]")?"[IndexedDB]: "+t:t,e}class I{constructor(e){this.anys=e}options(){return{namespace:new Error("options.namespace is required!"),autoReport:!1,expireTime:1728e5}}init(){const e="anyslogs",t=new b({name:this.anys.options.namespace,version:1,stores:[{name:e,primaryKeyPath:"_id",autoIncrement:!0}]});this.db=t.use(e),this.queue=new w;const{expireTime:n}=this.anys.options;if(n){let e=0;const t=setInterval((()=>{this.queue.push((()=>this.db.some(100,e))).then((r=>{if(!r.length)return void clearInterval(t);const s=Date.now(),o=[];r.forEach((e=>{const{_id:t,time:r}=e;s-r>n&&o.push(t)})),o.length&&this.queue.push((()=>this.db.delete(o))),e+=100,e-=o.length}))}),1e4)}}write(e){this.queue.push((()=>this.db.add(e))).then((t=>{this.anys.emit("writeOfflineLog",{id:t,data:e})}))}read(e){if(e){if(!Array.isArray(e))return;if(e.some((e=>!e.key)))return}else e=[{key:"client",value:this.anys.clientId},{key:"trace",value:this.anys.traceId}];return this.select(e)}clear(e){return this.queue.push((()=>this.db.remove(e))).catch((()=>{}))}select(e){return this.queue.push((()=>this.db.select(e)))}remove(e){return this.queue.push((()=>this.db.delete(e))).catch((()=>{}))}}class O extends a{options(){return{mutation:!0}}registerMutation(){const e=this.createObserver((e=>{const t={type:"mutation",time:Date.now(),detail:e};this.anys.write(t)}));return window.addEventListener("load",(()=>{e.observe(document,{characterData:!0,attributes:!0,childList:!0,subtree:!0}),this.recordSnapshot(),P(document.documentElement)})),()=>{e.disconnect()}}recordSnapshot(){const e=function(){const{name:e,publicId:t,systemId:n}=document.doctype,r={name:e,publicId:t,systemId:n},s=q(document.documentElement.innerHTML),o={},i=document.querySelector("html");for(let{name:e,value:t}of i.attributes)o[e]=t;const a=function(){const e=document.querySelectorAll("input, textarea, select"),t=[];return Array.from(e).forEach((e=>{const n=l(e),r="password"===e.type?"***":e.value;t.push({el:n,value:r})})),t}();return{doctype:r,attrs:o,html:s,values:a}}(),t=window.location.href,n=new URL(t),r=n.pathname.replace(/^([^/])/,"/$1");this.anys.write({type:"snapshot",time:Date.now(),url:{uri:r+(n.search?`?${n.search}`:""),path:r,protocol:n.protocol.replace(":",""),host:n.hostname,port:n.port,search:n.search,hash:n.hash.replace("#","")},detail:e})}createObserver(e){const t=new MutationObserver((t=>{const n=[];[...t].reverse().forEach((e=>{const{type:t,target:r,attributeName:s,oldValue:o}=e;if(!(e=>{if(e.hasAttribute?.("anys-ignore"))return!0;let t=e.parentNode;for(;t;){if(t.hasAttribute?.("anys-ignore"))return!0;t=t.parentNode}return!1})(r)){if("attributes"===t){if(r.getAttribute(s)===o)return;if(n.find((e=>e.type===t&&e.target===r&&e.attributeName===s)))return}else if("characterData"===t){const e=r.data;if(e===o)return;if(n.find((n=>n.type===t&&n.target===r&&n.target.data===e)))return}n.push(e)}})),n.reverse();const r=[];n.forEach((e=>{const{type:t,target:n,attributeName:s,oldValue:o}=e,i=n.path||l(n),a=e=>l(e).replace(i+"/","");if("attributes"===t){const e=n.getAttribute(s),t=o;r.push({type:"attribute",target:i,name:s,next:e,prev:t})}else if("characterData"===t){const e=n.data,t=o;r.push({type:"text",target:i,next:e,prev:t})}else if("childList"===t){if("TEXTAREA"===n.nodeName)return;const{removedNodes:t,addedNodes:s,previousSibling:o,nextSibling:c}=e,u=[],h=Array.from(t).map((e=>{if(document.body.contains(e))return void u.push({node:e,path:l(e)});const t=e.path?a(e):null,n=o?l(o):null,r=c?l(c):null,s={};return t?s.node=t:(s.before=n,s.after=r),s})).filter(Boolean),d=[],p=Array.from(s).map((e=>{const t=e.nextSibling?a(e.nextSibling):null,n=u.find((t=>t.node===e));if(n)return void d.push({node:n.path,sibling:t});const r="#text"===e.nodeName,s="#comment"===e.nodeName,o=r?e.data:null,i=s?e.data:null;return{text:o,html:r||s?null:q(e.outerHTML),comment:i,sibling:t}})).filter(Boolean);r.push({type:"children",target:i,remove:h,insert:p,move:d}),P(n)}})),e(r)}));return P(document),t}}function P(e){if(e!==document){const t=l(e);e.path=t}const t=e.childNodes;Array.from(t).forEach((e=>{P(e)}))}function q(e){return e.replace(/<script([^]*?)>([^]*?)<\/script>/gm,"<noscript$1></noscript>").replace(/<noscript([^]*?)>([^]*?)<\/noscript>/gm,"<noscript$1></noscript>").replace(/<link([^]*?)as="script"([^]*?)>/g,"<link$1$2>").replace(/\n\n*\s*\n*\n/gm,"\n")}class k extends a{options(){return{size:!0}}createRecordLog(){const{innerWidth:e,innerHeight:t}=window;return{type:"window_size",time:Date.now(),detail:{width:e,height:t}}}registerSize(){let e;const t=()=>{clearTimeout(e);const t=this.createRecordLog();e=setTimeout((()=>{this.anys.write(t)}),100)};return this.recordSize(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}}recordSize(){const e=this.createRecordLog();this.anys.write(e)}}class D extends a{options(){return{scroll:!0}}registerScroll(){let e=0;const t=t=>{if(e)return;const{target:n,bubbles:r}=t;let s;if(r){const{scrollX:e,scrollY:t}=window;s={type:"window_scroll",time:Date.now(),detail:{scrollX:e,scrollY:t}}}else{const{scrollLeft:e,scrollTop:t}=n;s={type:"scroll",time:Date.now(),target:l(n),detail:{scrollLeft:e,scrollTop:t}}}requestAnimationFrame((()=>{this.anys.write(s),e=0})),e=1};return window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("scroll",t)}}}class T extends a{static dependencies=[I,v,k,O,d,h,p,m,y,g,D];constructor(e,[t,n,r,s]){super(e),this.offlineStore=t,this.urlMonitor=n,this.windowSizeMonitor=r,this.DOMMutationMonitor=s,this.cache={}}options(){const e="ontouchend"in document;return{touch:e,mouse:!e,click:!1,mousedown:!0,mousemove:!0,mouseup:!0,autoReport:!1,reportUrl:new Error("options.reportUrl is required!"),reportInterval:1e4,reportParams:null}}registerAutoReport(){const{clientId:e}=this.anys,t=({prev:t})=>{this.anys.report([{key:"client",value:e},{key:"trace",value:t}]),this.cache={},this.urlMonitor.recordUrl(),this.windowSizeMonitor.recordSize(),this.DOMMutationMonitor.recordSnapshot()};this.anys.on("refreshTraceId",t);const n=setInterval((()=>{this.anys.report()}),this.anys.options.reportInterval);let r=0;const s=()=>{if(r)return;r=1;const e=Object.keys(this.cache),t=Object.values(this.cache);e.length&&(this.offlineStore.remove(e),navigator.sendBeacon(this.anys.options.reportUrl,JSON.stringify(t)),this.cache={})};window.addEventListener("beforeunload",s),window.addEventListener("pagehide",s),window.addEventListener("unload",s);const o=({id:e,data:t})=>{this.cache[e]=t};return this.anys.on("writeOfflineLog",o),()=>{this.anys.off("refreshTraceId",t),this.anys.off("writeOfflineLog",o),clearInterval(n),window.removeEventListener("beforeunload",s)}}read(e){return this.offlineStore.read(e)}send(e){const t=[];let n=0;e.forEach((e=>{t[n]=t[n]||[],t[n].push(e),t[n].length>200&&n++}));const r=t.map((e=>{const t=[],n=[];if(e.forEach((e=>{const{_id:r,...s}=e;n.push(r),t.push(s)})),!t.length)return;const{reportUrl:r,reportParams:s}=this.anys.options;return function(e,t){return new Promise(((n,r)=>{const s=new(window.__XMLHttpRequest||window.XMLHttpRequest);s.open("POST",e,!0),s.onreadystatechange=function(){4==s.readyState&&(200==s.status?n(s.responseText):r(new Error(`ajax post fail with status ${s.status}`)))},s.onerror=r,s.send(JSON.stringify(t))}))}(s?c(r,s):r,{data:t}).then((()=>{n.forEach((e=>{delete this.cache[e]}))}))}));return Promise.all(r)}clear(){this.cache={}}}class j extends i{auth(e){this.options.reportParams=Object.assign(this.options.reportParams||{},e)}}const A=(e={})=>new j({namespace:"AnysTracer",autoReport:!1,...e,plugins:{...e.plugins||{},recorder:T}})}();var n=anys="undefined"==typeof anys?{}:anys;for(var r in t)n[r]=t[r];t.__esModule&&Object.defineProperty(n,"__esModule",{value:!0})}();
2
2
  //# sourceMappingURL=index.js.map