@ohbug/extension-view 0.0.1 → 0.0.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.esm.js DELETED
@@ -1,442 +0,0 @@
1
- function createExtension(extension) {
2
- return extension;
3
- }
4
-
5
- const DEFAULT_TIMEOUT = 30 * 60 * 1000 ;
6
- class Session {
7
- constructor(timeout = DEFAULT_TIMEOUT) {
8
- this.session = null;
9
- this.timeout = DEFAULT_TIMEOUT;
10
- this.session = new Date().getTime();
11
- this.timeout = timeout;
12
- }
13
- /**
14
- * 检查当前 session 是否过期
15
- *
16
- * @returns {boolean}
17
- */
18
- isExpired() {
19
- if (!this.session) {
20
- throw new Error('Session 没有初始化');
21
- }
22
- const now = new Date().getTime();
23
- return this.session + this.timeout < now;
24
- }
25
- update() {
26
- if (!this.session) {
27
- throw new Error('Session 没有初始化');
28
- }
29
- const now = new Date().getTime();
30
- this.session = now;
31
- return this.session;
32
- }
33
- }
34
-
35
- function error(condition, format, ...args) {
36
- if (format === undefined) {
37
- throw new Error('`Ohbug warning(condition, format, ...args)` requires a warning message argument');
38
- }
39
- if (!condition) {
40
- let argIndex = 0;
41
- const message = format.replace(/%s/g, () => args[argIndex++]);
42
- throw new Error(`Ohbug ${message}`);
43
- }
44
- }
45
-
46
- const fallbackGlobalObject = {};
47
- function getGlobal() {
48
- return (typeof window !== 'undefined'
49
- ? window
50
- : typeof global !== 'undefined'
51
- ? global
52
- : typeof self !== 'undefined'
53
- ? self
54
- : fallbackGlobalObject);
55
- }
56
- function getOhbugObject() {
57
- const _global = getGlobal();
58
- error(Boolean(_global.__OHBUG__), 'Failed to get `OhbugObject`, please confirm if `Ohbug.init`');
59
- return _global.__OHBUG__;
60
- }
61
-
62
- function replace(source, name, behavior) {
63
- if (!(name in source)) {
64
- return;
65
- }
66
- const original = source[name];
67
- const wrapped = behavior(original);
68
- source[name] = wrapped;
69
- return original;
70
- }
71
- function parseUrl(url) {
72
- if (typeof url !== 'string') {
73
- return {};
74
- }
75
- // eslint-disable-next-line
76
- const match = url.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
77
- if (!match) {
78
- return {};
79
- }
80
- const query = match[6] || '';
81
- const fragment = match[8] || '';
82
- return {
83
- host: match[4],
84
- path: match[5],
85
- protocol: match[2],
86
- relative: match[5] + query + fragment,
87
- };
88
- }
89
-
90
- function sendPageView(path, initial) {
91
- const { client } = getOhbugObject();
92
- const event = client.createEvent({
93
- category: 'view',
94
- type: 'pageView',
95
- detail: {
96
- initial,
97
- path,
98
- },
99
- });
100
- client.notify(event);
101
- }
102
- function sendUserView(path) {
103
- const { client } = getOhbugObject();
104
- const event = client.createEvent({
105
- category: 'view',
106
- type: 'userView',
107
- detail: {
108
- path,
109
- },
110
- });
111
- client.notify(event);
112
- }
113
-
114
- function createCommonjsModule(fn) {
115
- var module = { exports: {} };
116
- return fn(module, module.exports), module.exports;
117
- }
118
-
119
- /*!
120
- * JavaScript Cookie v2.2.1
121
- * https://github.com/js-cookie/js-cookie
122
- *
123
- * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
124
- * Released under the MIT license
125
- */
126
-
127
- var js_cookie = createCommonjsModule(function (module, exports) {
128
- (function (factory) {
129
- var registeredInModuleLoader;
130
- {
131
- module.exports = factory();
132
- registeredInModuleLoader = true;
133
- }
134
- if (!registeredInModuleLoader) {
135
- var OldCookies = window.Cookies;
136
- var api = window.Cookies = factory();
137
- api.noConflict = function () {
138
- window.Cookies = OldCookies;
139
- return api;
140
- };
141
- }
142
- }(function () {
143
- function extend () {
144
- var i = 0;
145
- var result = {};
146
- for (; i < arguments.length; i++) {
147
- var attributes = arguments[ i ];
148
- for (var key in attributes) {
149
- result[key] = attributes[key];
150
- }
151
- }
152
- return result;
153
- }
154
-
155
- function decode (s) {
156
- return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
157
- }
158
-
159
- function init (converter) {
160
- function api() {}
161
-
162
- function set (key, value, attributes) {
163
- if (typeof document === 'undefined') {
164
- return;
165
- }
166
-
167
- attributes = extend({
168
- path: '/'
169
- }, api.defaults, attributes);
170
-
171
- if (typeof attributes.expires === 'number') {
172
- attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
173
- }
174
-
175
- // We're using "expires" because "max-age" is not supported by IE
176
- attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
177
-
178
- try {
179
- var result = JSON.stringify(value);
180
- if (/^[\{\[]/.test(result)) {
181
- value = result;
182
- }
183
- } catch (e) {}
184
-
185
- value = converter.write ?
186
- converter.write(value, key) :
187
- encodeURIComponent(String(value))
188
- .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
189
-
190
- key = encodeURIComponent(String(key))
191
- .replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
192
- .replace(/[\(\)]/g, escape);
193
-
194
- var stringifiedAttributes = '';
195
- for (var attributeName in attributes) {
196
- if (!attributes[attributeName]) {
197
- continue;
198
- }
199
- stringifiedAttributes += '; ' + attributeName;
200
- if (attributes[attributeName] === true) {
201
- continue;
202
- }
203
-
204
- // Considers RFC 6265 section 5.2:
205
- // ...
206
- // 3. If the remaining unparsed-attributes contains a %x3B (";")
207
- // character:
208
- // Consume the characters of the unparsed-attributes up to,
209
- // not including, the first %x3B (";") character.
210
- // ...
211
- stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
212
- }
213
-
214
- return (document.cookie = key + '=' + value + stringifiedAttributes);
215
- }
216
-
217
- function get (key, json) {
218
- if (typeof document === 'undefined') {
219
- return;
220
- }
221
-
222
- var jar = {};
223
- // To prevent the for loop in the first place assign an empty array
224
- // in case there are no cookies at all.
225
- var cookies = document.cookie ? document.cookie.split('; ') : [];
226
- var i = 0;
227
-
228
- for (; i < cookies.length; i++) {
229
- var parts = cookies[i].split('=');
230
- var cookie = parts.slice(1).join('=');
231
-
232
- if (!json && cookie.charAt(0) === '"') {
233
- cookie = cookie.slice(1, -1);
234
- }
235
-
236
- try {
237
- var name = decode(parts[0]);
238
- cookie = (converter.read || converter)(cookie, name) ||
239
- decode(cookie);
240
-
241
- if (json) {
242
- try {
243
- cookie = JSON.parse(cookie);
244
- } catch (e) {}
245
- }
246
-
247
- jar[name] = cookie;
248
-
249
- if (key === name) {
250
- break;
251
- }
252
- } catch (e) {}
253
- }
254
-
255
- return key ? jar[key] : jar;
256
- }
257
-
258
- api.set = set;
259
- api.get = function (key) {
260
- return get(key, false /* read as raw */);
261
- };
262
- api.getJSON = function (key) {
263
- return get(key, true /* read as json */);
264
- };
265
- api.remove = function (key, attributes) {
266
- set(key, '', extend(attributes, {
267
- expires: -1
268
- }));
269
- };
270
-
271
- api.defaults = {};
272
-
273
- api.withConverter = init;
274
-
275
- return api;
276
- }
277
-
278
- return init(function () {});
279
- }));
280
- });
281
-
282
- var dayjs_min = createCommonjsModule(function (module, exports) {
283
- !function(t,e){module.exports=e();}(this,function(){var t="millisecond",e="second",n="minute",r="hour",i="day",s="week",u="month",a="quarter",o="year",f="date",h=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},$=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},l={s:$,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+$(r,2,"0")+":"+$(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,u),s=n-i<0,a=e.clone().add(r+(s?-1:1),u);return +(-(r+(n-i)/(s?i-a:a-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(h){return {M:u,y:o,w:s,d:i,D:f,h:r,m:n,s:e,ms:t,Q:a}[h]||String(h||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},y="en",M={};M[y]=d;var m=function(t){return t instanceof S},D=function(t,e,n){var r;if(!t)return y;if("string"==typeof t)M[t]&&(r=t),e&&(M[t]=e,r=t);else {var i=t.name;M[i]=t,r=i;}return !n&&r&&(y=r),r||!n&&y},v=function(t,e){if(m(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new S(n)},g=l;g.l=D,g.i=m,g.w=function(t,e){return v(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var S=function(){function d(t){this.$L=D(t.locale,null,!0),this.parse(t);}var $=d.prototype;return $.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(g.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(h);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.$x=t.x||{},this.init();},$.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},$.$utils=function(){return g},$.isValid=function(){return !("Invalid Date"===this.$d.toString())},$.isSame=function(t,e){var n=v(t);return this.startOf(e)<=n&&n<=this.endOf(e)},$.isAfter=function(t,e){return v(t)<this.startOf(e)},$.isBefore=function(t,e){return this.endOf(e)<v(t)},$.$g=function(t,e,n){return g.u(t)?this[e]:this.set(n,t)},$.unix=function(){return Math.floor(this.valueOf()/1e3)},$.valueOf=function(){return this.$d.getTime()},$.startOf=function(t,a){var h=this,c=!!g.u(a)||a,d=g.p(t),$=function(t,e){var n=g.w(h.$u?Date.UTC(h.$y,e,t):new Date(h.$y,e,t),h);return c?n:n.endOf(i)},l=function(t,e){return g.w(h.toDate()[t].apply(h.toDate("s"),(c?[0,0,0,0]:[23,59,59,999]).slice(e)),h)},y=this.$W,M=this.$M,m=this.$D,D="set"+(this.$u?"UTC":"");switch(d){case o:return c?$(1,0):$(31,11);case u:return c?$(1,M):$(0,M+1);case s:var v=this.$locale().weekStart||0,S=(y<v?y+7:y)-v;return $(c?m-S:m+(6-S),M);case i:case f:return l(D+"Hours",0);case r:return l(D+"Minutes",1);case n:return l(D+"Seconds",2);case e:return l(D+"Milliseconds",3);default:return this.clone()}},$.endOf=function(t){return this.startOf(t,!1)},$.$set=function(s,a){var h,c=g.p(s),d="set"+(this.$u?"UTC":""),$=(h={},h[i]=d+"Date",h[f]=d+"Date",h[u]=d+"Month",h[o]=d+"FullYear",h[r]=d+"Hours",h[n]=d+"Minutes",h[e]=d+"Seconds",h[t]=d+"Milliseconds",h)[c],l=c===i?this.$D+(a-this.$W):a;if(c===u||c===o){var y=this.clone().set(f,1);y.$d[$](l),y.init(),this.$d=y.set(f,Math.min(this.$D,y.daysInMonth())).$d;}else $&&this.$d[$](l);return this.init(),this},$.set=function(t,e){return this.clone().$set(t,e)},$.get=function(t){return this[g.p(t)]()},$.add=function(t,a){var f,h=this;t=Number(t);var c=g.p(a),d=function(e){var n=v(h);return g.w(n.date(n.date()+Math.round(e*t)),h)};if(c===u)return this.set(u,this.$M+t);if(c===o)return this.set(o,this.$y+t);if(c===i)return d(1);if(c===s)return d(7);var $=(f={},f[n]=6e4,f[r]=36e5,f[e]=1e3,f)[c]||1,l=this.$d.getTime()+t*$;return g.w(l,this)},$.subtract=function(t,e){return this.add(-1*t,e)},$.format=function(t){var e=this;if(!this.isValid())return "Invalid Date";var n=t||"YYYY-MM-DDTHH:mm:ssZ",r=g.z(this),i=this.$locale(),s=this.$H,u=this.$m,a=this.$M,o=i.weekdays,f=i.months,h=function(t,r,i,s){return t&&(t[r]||t(e,n))||i[r].substr(0,s)},d=function(t){return g.s(s%12||12,t,"0")},$=i.meridiem||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r},l={YY:String(this.$y).slice(-2),YYYY:this.$y,M:a+1,MM:g.s(a+1,2,"0"),MMM:h(i.monthsShort,a,f,3),MMMM:h(f,a),D:this.$D,DD:g.s(this.$D,2,"0"),d:String(this.$W),dd:h(i.weekdaysMin,this.$W,o,2),ddd:h(i.weekdaysShort,this.$W,o,3),dddd:o[this.$W],H:String(s),HH:g.s(s,2,"0"),h:d(1),hh:d(2),a:$(s,u,!0),A:$(s,u,!1),m:String(u),mm:g.s(u,2,"0"),s:String(this.$s),ss:g.s(this.$s,2,"0"),SSS:g.s(this.$ms,3,"0"),Z:r};return n.replace(c,function(t,e){return e||l[t]||r.replace(":","")})},$.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},$.diff=function(t,f,h){var c,d=g.p(f),$=v(t),l=6e4*($.utcOffset()-this.utcOffset()),y=this-$,M=g.m(this,$);return M=(c={},c[o]=M/12,c[u]=M,c[a]=M/3,c[s]=(y-l)/6048e5,c[i]=(y-l)/864e5,c[r]=y/36e5,c[n]=y/6e4,c[e]=y/1e3,c)[d]||y,h?M:g.a(M)},$.daysInMonth=function(){return this.endOf(u).$D},$.$locale=function(){return M[this.$L]},$.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=D(t,e,!0);return r&&(n.$L=r),n},$.clone=function(){return g.w(this.$d,this)},$.toDate=function(){return new Date(this.valueOf())},$.toJSON=function(){return this.isValid()?this.toISOString():null},$.toISOString=function(){return this.$d.toISOString()},$.toString=function(){return this.$d.toUTCString()},d}(),p=S.prototype;return v.prototype=p,[["$ms",t],["$s",e],["$m",n],["$H",r],["$W",i],["$M",u],["$y",o],["$D",f]].forEach(function(t){p[t[1]]=function(e){return this.$g(e,t[0],t[1])};}),v.extend=function(t,e){return t.$i||(t(e,S,v),t.$i=!0),v},v.locale=D,v.isDayjs=m,v.unix=function(t){return v(1e3*t)},v.en=M[y],v.Ls=M,v.p={},v});
284
- });
285
-
286
- const NAME = 'OhbugExtensionViewUV';
287
- /**
288
- * initial page view 触发时同时触发
289
- * 先从 cookie 内取值
290
- * 没有值 => 创建 cookie 并记一次 uv
291
- * 有值(当天) => 不动
292
- * 有值(昨天) => 更新 cookie 并记一次 uv
293
- * 有值(明天) => 不动 (不应出现这个情况)
294
- */
295
- function createUserView(path) {
296
- const value = js_cookie.get(NAME);
297
- // 没有值 => 创建 cookie 并记一次 uv
298
- if (!value) {
299
- js_cookie.set(NAME, dayjs_min().toISOString(), { expires: 30 });
300
- sendUserView(path);
301
- }
302
- else {
303
- const parsedValue = dayjs_min(value);
304
- // 有值(昨天) => 更新 cookie 并记一次 uv
305
- if (parsedValue.isBefore(dayjs_min(), 'day')) {
306
- js_cookie.set(NAME, dayjs_min().toISOString(), { expires: 30 });
307
- sendUserView(path);
308
- }
309
- }
310
- }
311
-
312
- const HIDDEN = 'hidden';
313
- const VISIBLE = 'visible';
314
- /**
315
- * 1. 页面加载时,如果页面的 visibilityState 是可见的,发送 Page View 统计
316
- * 2. 如果页面的 visibilityState 是隐藏的,就监听 visibilitychange 事件,并在 visibilityState 变为可见时发送 Page View 统计
317
- * 3. 如果 visibilityState 由隐藏变为可见,并且自上次用户交互之后已经过了“足够长”的时间,就发送新的 Page View 统计
318
- * 4. 如果 URL 发生变化 发送新的 Page View 统计
319
- */
320
- class PageVisibility {
321
- constructor() {
322
- this.visible = null;
323
- this.lastVisible = null;
324
- this.initialVisible = null;
325
- this.sendPageLoad = false;
326
- this.visibleThresholdTimeout = null;
327
- this.handleVisibleChange = this.handleVisibleChange.bind(this);
328
- window.addEventListener('visibilitychange', this.handleVisibleChange, true);
329
- this.init();
330
- this.session = new Session();
331
- }
332
- static capturePageVisibility() {
333
- return new PageVisibility();
334
- }
335
- init() {
336
- // 页面加载时,如果页面的 visibilityState 是可见的,发送 Page View 统计
337
- if (!this.sendPageLoad) {
338
- if (document.visibilityState === VISIBLE) {
339
- this.initialVisible = true;
340
- sendPageView(window.location.href, true);
341
- createUserView(window.location.href);
342
- this.sendPageLoad = true;
343
- }
344
- else {
345
- this.initialVisible = false;
346
- }
347
- }
348
- }
349
- handleVisibleChange() {
350
- this.lastVisible = this.visible;
351
- if (document.visibilityState === VISIBLE) {
352
- this.visible = true;
353
- }
354
- else if (document.visibilityState === HIDDEN) {
355
- this.visible = false;
356
- }
357
- else {
358
- this.visible = null;
359
- }
360
- const { visible, lastVisible, initialVisible, session } = this;
361
- // 如果页面的 visibilityState 是隐藏的,就监听 visibilitychange 事件,并在 visibilityState 变为可见时发送 Page View 统计
362
- if (initialVisible === false && visible === true) {
363
- sendPageView(window.location.href, true);
364
- createUserView(window.location.href);
365
- // 发送后将 initialVisible 置空 防止重复发送
366
- this.initialVisible = null;
367
- }
368
- // 如果 visibilityState 由隐藏变为可见,并且自上次用户交互之后已经过了“足够长”的时间,就发送新的 Page View 统计
369
- if (lastVisible === false && visible === true) {
370
- if (session.isExpired()) {
371
- sendPageView(window.location.href);
372
- createUserView(window.location.href);
373
- }
374
- }
375
- if (visible === false) {
376
- session.update();
377
- }
378
- }
379
- }
380
-
381
- let lastHref;
382
- function handleUrlChange(from, to) {
383
- const parsedHref = parseUrl(window?.location?.href);
384
- let parsedFrom = parseUrl(from);
385
- const parsedTo = parseUrl(to);
386
- if (!parsedFrom.path) {
387
- parsedFrom = parsedHref;
388
- }
389
- lastHref = to;
390
- let targetFrom = from;
391
- let targetTo = to;
392
- if (parsedHref.protocol === parsedTo.protocol &&
393
- parsedHref.host === parsedTo.host) {
394
- targetTo = parsedTo.relative;
395
- }
396
- if (parsedHref.protocol === parsedFrom.protocol &&
397
- parsedHref.host === parsedFrom.host) {
398
- targetFrom = parsedFrom.relative;
399
- }
400
- if (targetFrom === targetTo)
401
- return;
402
- sendPageView(targetTo);
403
- }
404
- function historyReplacement(original) {
405
- return function call(data, title, url) {
406
- if (url) {
407
- handleUrlChange(lastHref, String(url));
408
- }
409
- return original.apply(this, [data, title, url]);
410
- };
411
- }
412
- function historyListener() {
413
- replace(window?.history, 'pushState', historyReplacement);
414
- replace(window?.history, 'replaceState', historyReplacement);
415
- replace(window, 'onpopstate', () => {
416
- const current = window?.location?.href;
417
- handleUrlChange(lastHref, current);
418
- });
419
- }
420
- function hashListener(e) {
421
- const { oldURL, newURL } = e;
422
- handleUrlChange(oldURL, newURL);
423
- }
424
- /**
425
- * 如果 URL 发生变化 发送新的 Page View 统计
426
- */
427
- function captureUrlChange() {
428
- // history
429
- historyListener();
430
- // hash
431
- window?.addEventListener?.('hashchange', hashListener, true);
432
- }
433
-
434
- const extension = createExtension({
435
- name: 'OhbugExtensionView',
436
- init: () => {
437
- PageVisibility.capturePageVisibility();
438
- captureUrlChange();
439
- },
440
- });
441
-
442
- export default extension;
@@ -1,8 +0,0 @@
1
- class t{constructor(t=18e5){this.session=null,this.timeout=18e5,this.session=(new Date).getTime(),this.timeout=t}isExpired(){if(!this.session)throw new Error("Session 没有初始化");const t=(new Date).getTime();return this.session+this.timeout<t}update(){if(!this.session)throw new Error("Session 没有初始化");const t=(new Date).getTime();return this.session=t,this.session}}const e={};function n(){const t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:e;return function(t,e,...n){if(void 0===e)throw new Error("`Ohbug warning(condition, format, ...args)` requires a warning message argument");if(!t){let t=0;const i=e.replace(/%s/g,(()=>n[t++]));throw new Error(`Ohbug ${i}`)}}(Boolean(t.__OHBUG__),"Failed to get `OhbugObject`, please confirm if `Ohbug.init`"),t.__OHBUG__}function i(t,e,n){if(!(e in t))return;const i=t[e],r=n(i);return t[e]=r,i}function r(t){if("string"!=typeof t)return{};const e=t.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!e)return{};const n=e[6]||"",i=e[8]||"";return{host:e[4],path:e[5],protocol:e[2],relative:e[5]+n+i}}function s(t,e){const{client:i}=n(),r=i.createEvent({category:"view",type:"pageView",detail:{initial:e,path:t}});i.notify(r)}function o(t){const{client:e}=n(),i=e.createEvent({category:"view",type:"userView",detail:{path:t}});e.notify(i)}function a(t){var e={exports:{}};return t(e,e.exports),e.exports
2
- /*!
3
- * JavaScript Cookie v2.2.1
4
- * https://github.com/js-cookie/js-cookie
5
- *
6
- * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
7
- * Released under the MIT license
8
- */}var u=a((function(t,e){var n;n=function(){function t(){for(var t=0,e={};t<arguments.length;t++){var n=arguments[t];for(var i in n)e[i]=n[i]}return e}function e(t){return t.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(i){function r(){}function s(e,n,s){if("undefined"!=typeof document){"number"==typeof(s=t({path:"/"},r.defaults,s)).expires&&(s.expires=new Date(1*new Date+864e5*s.expires)),s.expires=s.expires?s.expires.toUTCString():"";try{var o=JSON.stringify(n);/^[\{\[]/.test(o)&&(n=o)}catch(t){}n=i.write?i.write(n,e):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var u in s)s[u]&&(a+="; "+u,!0!==s[u]&&(a+="="+s[u].split(";")[0]));return document.cookie=e+"="+n+a}}function o(t,n){if("undefined"!=typeof document){for(var r={},s=document.cookie?document.cookie.split("; "):[],o=0;o<s.length;o++){var a=s[o].split("="),u=a.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var c=e(a[0]);if(u=(i.read||i)(u,c)||e(u),n)try{u=JSON.parse(u)}catch(t){}if(r[c]=u,t===c)break}catch(t){}}return t?r[t]:r}}return r.set=s,r.get=function(t){return o(t,!1)},r.getJSON=function(t){return o(t,!0)},r.remove=function(e,n){s(e,"",t(n,{expires:-1}))},r.defaults={},r.withConverter=n,r}((function(){}))},t.exports=n()})),c=a((function(t,e){t.exports=function(){var t="millisecond",e="second",n="minute",i="hour",r="day",s="week",o="month",a="quarter",u="year",c="date",h=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,f=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,l={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},d=function(t,e,n){var i=String(t);return!i||i.length>=e?t:""+Array(e+1-i.length).join(n)+t},p={s:d,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),i=Math.floor(n/60),r=n%60;return(e<=0?"+":"-")+d(i,2,"0")+":"+d(r,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var i=12*(n.year()-e.year())+(n.month()-e.month()),r=e.clone().add(i,o),s=n-r<0,a=e.clone().add(i+(s?-1:1),o);return+(-(i+(n-r)/(s?r-a:a-r))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(h){return{M:o,y:u,w:s,d:r,D:c,h:i,m:n,s:e,ms:t,Q:a}[h]||String(h||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",w={};w[g]=l;var $=function(t){return t instanceof S},v=function(t,e,n){var i;if(!t)return g;if("string"==typeof t)w[t]&&(i=t),e&&(w[t]=e,i=t);else{var r=t.name;w[r]=t,i=r}return!n&&i&&(g=i),i||!n&&g},m=function(t,e){if($(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new S(n)},y=p;y.l=v,y.i=$,y.w=function(t,e){return m(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var S=function(){function l(t){this.$L=v(t.locale,null,!0),this.parse(t)}var d=l.prototype;return d.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(y.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var i=e.match(h);if(i){var r=i[2]-1||0,s=(i[7]||"0").substring(0,3);return n?new Date(Date.UTC(i[1],r,i[3]||1,i[4]||0,i[5]||0,i[6]||0,s)):new Date(i[1],r,i[3]||1,i[4]||0,i[5]||0,i[6]||0,s)}}return new Date(e)}(t),this.$x=t.x||{},this.init()},d.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},d.$utils=function(){return y},d.isValid=function(){return!("Invalid Date"===this.$d.toString())},d.isSame=function(t,e){var n=m(t);return this.startOf(e)<=n&&n<=this.endOf(e)},d.isAfter=function(t,e){return m(t)<this.startOf(e)},d.isBefore=function(t,e){return this.endOf(e)<m(t)},d.$g=function(t,e,n){return y.u(t)?this[e]:this.set(n,t)},d.unix=function(){return Math.floor(this.valueOf()/1e3)},d.valueOf=function(){return this.$d.getTime()},d.startOf=function(t,a){var h=this,f=!!y.u(a)||a,l=y.p(t),d=function(t,e){var n=y.w(h.$u?Date.UTC(h.$y,e,t):new Date(h.$y,e,t),h);return f?n:n.endOf(r)},p=function(t,e){return y.w(h.toDate()[t].apply(h.toDate("s"),(f?[0,0,0,0]:[23,59,59,999]).slice(e)),h)},g=this.$W,w=this.$M,$=this.$D,v="set"+(this.$u?"UTC":"");switch(l){case u:return f?d(1,0):d(31,11);case o:return f?d(1,w):d(0,w+1);case s:var m=this.$locale().weekStart||0,S=(g<m?g+7:g)-m;return d(f?$-S:$+(6-S),w);case r:case c:return p(v+"Hours",0);case i:return p(v+"Minutes",1);case n:return p(v+"Seconds",2);case e:return p(v+"Milliseconds",3);default:return this.clone()}},d.endOf=function(t){return this.startOf(t,!1)},d.$set=function(s,a){var h,f=y.p(s),l="set"+(this.$u?"UTC":""),d=(h={},h[r]=l+"Date",h[c]=l+"Date",h[o]=l+"Month",h[u]=l+"FullYear",h[i]=l+"Hours",h[n]=l+"Minutes",h[e]=l+"Seconds",h[t]=l+"Milliseconds",h)[f],p=f===r?this.$D+(a-this.$W):a;if(f===o||f===u){var g=this.clone().set(c,1);g.$d[d](p),g.init(),this.$d=g.set(c,Math.min(this.$D,g.daysInMonth())).$d}else d&&this.$d[d](p);return this.init(),this},d.set=function(t,e){return this.clone().$set(t,e)},d.get=function(t){return this[y.p(t)]()},d.add=function(t,a){var c,h=this;t=Number(t);var f=y.p(a),l=function(e){var n=m(h);return y.w(n.date(n.date()+Math.round(e*t)),h)};if(f===o)return this.set(o,this.$M+t);if(f===u)return this.set(u,this.$y+t);if(f===r)return l(1);if(f===s)return l(7);var d=(c={},c[n]=6e4,c[i]=36e5,c[e]=1e3,c)[f]||1,p=this.$d.getTime()+t*d;return y.w(p,this)},d.subtract=function(t,e){return this.add(-1*t,e)},d.format=function(t){var e=this;if(!this.isValid())return"Invalid Date";var n=t||"YYYY-MM-DDTHH:mm:ssZ",i=y.z(this),r=this.$locale(),s=this.$H,o=this.$m,a=this.$M,u=r.weekdays,c=r.months,h=function(t,i,r,s){return t&&(t[i]||t(e,n))||r[i].substr(0,s)},l=function(t){return y.s(s%12||12,t,"0")},d=r.meridiem||function(t,e,n){var i=t<12?"AM":"PM";return n?i.toLowerCase():i},p={YY:String(this.$y).slice(-2),YYYY:this.$y,M:a+1,MM:y.s(a+1,2,"0"),MMM:h(r.monthsShort,a,c,3),MMMM:h(c,a),D:this.$D,DD:y.s(this.$D,2,"0"),d:String(this.$W),dd:h(r.weekdaysMin,this.$W,u,2),ddd:h(r.weekdaysShort,this.$W,u,3),dddd:u[this.$W],H:String(s),HH:y.s(s,2,"0"),h:l(1),hh:l(2),a:d(s,o,!0),A:d(s,o,!1),m:String(o),mm:y.s(o,2,"0"),s:String(this.$s),ss:y.s(this.$s,2,"0"),SSS:y.s(this.$ms,3,"0"),Z:i};return n.replace(f,(function(t,e){return e||p[t]||i.replace(":","")}))},d.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},d.diff=function(t,c,h){var f,l=y.p(c),d=m(t),p=6e4*(d.utcOffset()-this.utcOffset()),g=this-d,w=y.m(this,d);return w=(f={},f[u]=w/12,f[o]=w,f[a]=w/3,f[s]=(g-p)/6048e5,f[r]=(g-p)/864e5,f[i]=g/36e5,f[n]=g/6e4,f[e]=g/1e3,f)[l]||g,h?w:y.a(w)},d.daysInMonth=function(){return this.endOf(o).$D},d.$locale=function(){return w[this.$L]},d.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),i=v(t,e,!0);return i&&(n.$L=i),n},d.clone=function(){return y.w(this.$d,this)},d.toDate=function(){return new Date(this.valueOf())},d.toJSON=function(){return this.isValid()?this.toISOString():null},d.toISOString=function(){return this.$d.toISOString()},d.toString=function(){return this.$d.toUTCString()},l}(),b=S.prototype;return m.prototype=b,[["$ms",t],["$s",e],["$m",n],["$H",i],["$W",r],["$M",o],["$y",u],["$D",c]].forEach((function(t){b[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),m.extend=function(t,e){return t.$i||(t(e,S,m),t.$i=!0),m},m.locale=v,m.isDayjs=$,m.unix=function(t){return m(1e3*t)},m.en=w[g],m.Ls=w,m.p={},m}()}));const h="OhbugExtensionViewUV";function f(t){const e=u.get(h);if(e){c(e).isBefore(c(),"day")&&(u.set(h,c().toISOString(),{expires:30}),o(t))}else u.set(h,c().toISOString(),{expires:30}),o(t)}class l{constructor(){this.visible=null,this.lastVisible=null,this.initialVisible=null,this.sendPageLoad=!1,this.visibleThresholdTimeout=null,this.handleVisibleChange=this.handleVisibleChange.bind(this),window.addEventListener("visibilitychange",this.handleVisibleChange,!0),this.init(),this.session=new t}static capturePageVisibility(){return new l}init(){this.sendPageLoad||("visible"===document.visibilityState?(this.initialVisible=!0,s(window.location.href,!0),f(window.location.href),this.sendPageLoad=!0):this.initialVisible=!1)}handleVisibleChange(){this.lastVisible=this.visible,"visible"===document.visibilityState?this.visible=!0:"hidden"===document.visibilityState?this.visible=!1:this.visible=null;const{visible:t,lastVisible:e,initialVisible:n,session:i}=this;!1===n&&!0===t&&(s(window.location.href,!0),f(window.location.href),this.initialVisible=null),!1===e&&!0===t&&i.isExpired()&&(s(window.location.href),f(window.location.href)),!1===t&&i.update()}}let d;function p(t,e){const n=r(window?.location?.href);let i=r(t);const o=r(e);i.path||(i=n),d=e;let a=t,u=e;n.protocol===o.protocol&&n.host===o.host&&(u=o.relative),n.protocol===i.protocol&&n.host===i.host&&(a=i.relative),a!==u&&s(u)}function g(t){return function(e,n,i){return i&&p(d,String(i)),t.apply(this,[e,n,i])}}function w(t){const{oldURL:e,newURL:n}=t;p(e,n)}function $(){i(window?.history,"pushState",g),i(window?.history,"replaceState",g),i(window,"onpopstate",(()=>{const t=window?.location?.href;p(d,t)})),window?.addEventListener?.("hashchange",w,!0)}const v={name:"OhbugExtensionView",init:()=>{l.capturePageVisibility(),$()}};export default v;