@cloudcare/browser-core 2.0.4 → 2.0.5

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.
Files changed (97) hide show
  1. package/cjs/browser/addEventListener.js +57 -0
  2. package/cjs/browser/pageExitObservable.js +4 -2
  3. package/cjs/browser/runOnReadyState.js +21 -0
  4. package/cjs/browser/xhrObservable.js +7 -5
  5. package/cjs/configuration/configuration.js +5 -3
  6. package/cjs/console/consoleObservable.js +3 -1
  7. package/cjs/dataMap.js +1 -0
  8. package/cjs/helper/byteUtils.js +26 -0
  9. package/cjs/helper/contextHistory.js +4 -2
  10. package/cjs/helper/createEventRateLimiter.js +3 -1
  11. package/cjs/helper/errorTools.js +4 -2
  12. package/cjs/helper/instrumentMethod.js +2 -4
  13. package/cjs/helper/serialisation/contextManager.js +84 -0
  14. package/cjs/helper/serialisation/heavyCustomerDataWarning.js +34 -0
  15. package/cjs/helper/serialisation/jsonStringify.js +57 -0
  16. package/cjs/helper/serialisation/rowData.js +50 -0
  17. package/cjs/helper/timer.js +29 -0
  18. package/cjs/helper/tools.js +10 -331
  19. package/cjs/index.js +117 -0
  20. package/cjs/init.js +6 -6
  21. package/cjs/report/reportObservable.js +4 -2
  22. package/cjs/session/sessionCookieStore.js +3 -1
  23. package/cjs/session/sessionManagement.js +10 -5
  24. package/cjs/session/sessionStore.js +10 -4
  25. package/cjs/transport/batch.js +40 -91
  26. package/cjs/transport/flushController.js +121 -0
  27. package/cjs/transport/httpRequest.js +6 -2
  28. package/cjs/transport/index.js +9 -1
  29. package/cjs/transport/sendWithRetryStrategy.js +8 -4
  30. package/cjs/transport/startBatchWithReplica.js +10 -2
  31. package/cjs/user/index.js +18 -0
  32. package/cjs/user/user.js +42 -0
  33. package/esm/browser/addEventListener.js +46 -0
  34. package/esm/browser/pageExitObservable.js +2 -1
  35. package/esm/browser/runOnReadyState.js +12 -0
  36. package/esm/browser/xhrObservable.js +6 -5
  37. package/esm/configuration/configuration.js +2 -1
  38. package/esm/console/consoleObservable.js +2 -1
  39. package/esm/dataMap.js +1 -0
  40. package/esm/helper/byteUtils.js +16 -0
  41. package/esm/helper/contextHistory.js +1 -0
  42. package/esm/helper/createEventRateLimiter.js +1 -0
  43. package/esm/helper/errorTools.js +2 -1
  44. package/esm/helper/instrumentMethod.js +1 -3
  45. package/esm/helper/serialisation/contextManager.js +70 -0
  46. package/esm/helper/serialisation/heavyCustomerDataWarning.js +20 -0
  47. package/esm/helper/serialisation/jsonStringify.js +46 -0
  48. package/esm/helper/serialisation/rowData.js +33 -0
  49. package/esm/helper/timer.js +14 -0
  50. package/esm/helper/tools.js +1 -292
  51. package/esm/index.js +10 -1
  52. package/esm/init.js +6 -6
  53. package/esm/report/reportObservable.js +3 -2
  54. package/esm/session/sessionCookieStore.js +1 -0
  55. package/esm/session/sessionManagement.js +5 -2
  56. package/esm/session/sessionStore.js +7 -2
  57. package/esm/transport/batch.js +31 -85
  58. package/esm/transport/flushController.js +114 -0
  59. package/esm/transport/httpRequest.js +5 -2
  60. package/esm/transport/index.js +2 -1
  61. package/esm/transport/sendWithRetryStrategy.js +3 -1
  62. package/esm/transport/startBatchWithReplica.js +9 -2
  63. package/esm/user/index.js +1 -0
  64. package/esm/user/user.js +32 -0
  65. package/package.json +22 -22
  66. package/src/browser/addEventListener.js +50 -0
  67. package/src/browser/pageExitObservable.js +4 -5
  68. package/src/browser/runOnReadyState.js +16 -0
  69. package/src/browser/xhrObservable.js +57 -32
  70. package/src/configuration/configuration.js +1 -1
  71. package/src/console/consoleObservable.js +22 -12
  72. package/src/dataMap.js +1 -0
  73. package/src/helper/byteUtils.js +17 -0
  74. package/src/helper/contextHistory.js +1 -1
  75. package/src/helper/createEventRateLimiter.js +7 -9
  76. package/src/helper/errorTools.js +2 -1
  77. package/src/helper/instrumentMethod.js +1 -2
  78. package/src/helper/serialisation/contextManager.js +79 -0
  79. package/src/helper/serialisation/heavyCustomerDataWarning.js +28 -0
  80. package/src/helper/serialisation/jsonStringify.js +47 -0
  81. package/src/helper/serialisation/rowData.js +41 -0
  82. package/src/helper/timer.js +21 -0
  83. package/src/helper/tools.js +2 -301
  84. package/src/index.js +11 -0
  85. package/src/init.js +6 -6
  86. package/src/report/reportObservable.js +40 -25
  87. package/src/session/sessionCookieStore.js +24 -14
  88. package/src/session/sessionManagement.js +34 -17
  89. package/src/session/sessionStore.js +7 -2
  90. package/src/transport/batch.js +39 -91
  91. package/src/transport/flushController.js +115 -0
  92. package/src/transport/httpRequest.js +13 -6
  93. package/src/transport/index.js +1 -0
  94. package/src/transport/sendWithRetryStrategy.js +3 -7
  95. package/src/transport/startBatchWithReplica.js +11 -7
  96. package/src/user/index.js +1 -0
  97. package/src/user/user.js +31 -0
@@ -1,6 +1,7 @@
1
1
  import { Observable } from '../helper/observable';
2
- import { addEventListener, addEventListeners, includes, values } from '../helper/tools';
2
+ import { includes, values } from '../helper/tools';
3
3
  import { DOM_EVENT } from '../helper/enums';
4
+ import { addEventListener, addEventListeners } from '../browser/addEventListener';
4
5
  export var PageExitReason = {
5
6
  HIDDEN: 'visibility_hidden',
6
7
  UNLOADING: 'before_unload',
@@ -0,0 +1,12 @@
1
+ import { addEventListener } from './addEventListener';
2
+ import { DOM_EVENT } from '../helper/enums';
3
+ export function runOnReadyState(expectedReadyState, callback) {
4
+ if (document.readyState === expectedReadyState || document.readyState === 'complete') {
5
+ callback();
6
+ } else {
7
+ var eventName = expectedReadyState === 'complete' ? DOM_EVENT.LOAD : DOM_EVENT.DOM_CONTENT_LOADED;
8
+ addEventListener(window, eventName, callback, {
9
+ once: true
10
+ });
11
+ }
12
+ }
@@ -2,6 +2,7 @@ import { instrumentMethodAndCallOriginal } from '../helper/instrumentMethod';
2
2
  import { Observable } from '../helper/observable';
3
3
  import { normalizeUrl } from '../helper/urlPolyfill';
4
4
  import { shallowClone, elapsed, relativeNow, clocksNow, timeStampNow, UUID } from '../helper/tools';
5
+ import { addEventListener } from '../browser/addEventListener';
5
6
  var xhrObservable;
6
7
  var xhrContexts = {};
7
8
  var DATA_FLUX_REQUEST_ID_KEY = '_DATAFLUX_REQUEST_UUID';
@@ -59,7 +60,7 @@ function sendXhr(observable) {
59
60
  startContext.isAborted = false;
60
61
  startContext.xhr = this;
61
62
  var hasBeenReported = false;
62
- var onreadyStateChangeInstrumentMethod = instrumentMethodAndCallOriginal(this, 'onreadystatechange', {
63
+ var stopInstrumentingOnReadyStateChange = instrumentMethodAndCallOriginal(this, 'onreadystatechange', {
63
64
  before: function before() {
64
65
  if (this.readyState === XMLHttpRequest.DONE) {
65
66
  // Try to report the XHR as soon as possible, because the XHR may be mutated by the
@@ -69,11 +70,11 @@ function sendXhr(observable) {
69
70
  onEnd.call(this);
70
71
  }
71
72
  }
72
- });
73
+ }).stop;
73
74
 
74
75
  var onEnd = function onEnd() {
75
- this.removeEventListener('loadend', onEnd);
76
- onreadyStateChangeInstrumentMethod.stop();
76
+ unsubscribeLoadEndListener();
77
+ stopInstrumentingOnReadyStateChange();
77
78
 
78
79
  if (hasBeenReported) {
79
80
  return;
@@ -88,7 +89,7 @@ function sendXhr(observable) {
88
89
  clearRequestId.call(this);
89
90
  };
90
91
 
91
- this.addEventListener('loadend', onEnd);
92
+ var unsubscribeLoadEndListener = addEventListener(this, 'loadend', onEnd).stop;
92
93
  observable.notify(startContext);
93
94
  }
94
95
 
@@ -1,7 +1,8 @@
1
1
  import { getCurrentSite } from '../browser/cookie';
2
2
  import { catchUserErrors } from '../helper/catchUserErrors';
3
3
  import { display } from '../helper/display';
4
- import { assign, isPercentage, ONE_KIBI_BYTE, ONE_SECOND, isNullUndefinedDefaultValue } from '../helper/tools';
4
+ import { assign, isPercentage, ONE_SECOND, isNullUndefinedDefaultValue } from '../helper/tools';
5
+ import { ONE_KIBI_BYTE } from '../helper/byteUtils';
5
6
  import { computeTransportConfiguration } from './transportConfiguration';
6
7
  export var DefaultPrivacyLevel = {
7
8
  ALLOW: 'allow',
@@ -1,7 +1,8 @@
1
1
  import { computeStackTrace } from '../tracekit';
2
2
  import { createHandlingStack, formatErrorMessage, toStackTraceString } from '../helper/errorTools';
3
3
  import { mergeObservables, Observable } from '../helper/observable';
4
- import { find, jsonStringify, map } from '../helper/tools';
4
+ import { find, map } from '../helper/tools';
5
+ import { jsonStringify } from '../helper/serialisation/jsonStringify';
5
6
  import { ConsoleApiName } from '../helper/display';
6
7
  var consoleObservablesByApi = {};
7
8
  export function initConsoleObservable(apis) {
package/esm/dataMap.js CHANGED
@@ -48,6 +48,7 @@ export var dataMap = {
48
48
  },
49
49
  fields: {
50
50
  session_replay_stats: '_dd.replay_stats',
51
+ session_is_active: 'session.is_active',
51
52
  view_error_count: 'view.error.count',
52
53
  view_resource_count: 'view.resource.count',
53
54
  view_long_task_count: 'view.long_task.count',
@@ -0,0 +1,16 @@
1
+ export var ONE_KIBI_BYTE = 1024;
2
+ export var ONE_MEBI_BYTE = 1024 * ONE_KIBI_BYTE; // eslint-disable-next-line no-control-regex
3
+
4
+ var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
5
+ export function computeBytesCount(candidate) {
6
+ // Accurate bytes count computations can degrade performances when there is a lot of events to process
7
+ if (!HAS_MULTI_BYTES_CHARACTERS.test(candidate)) {
8
+ return candidate.length;
9
+ }
10
+
11
+ if (window.TextEncoder !== undefined) {
12
+ return new TextEncoder().encode(candidate).length;
13
+ }
14
+
15
+ return new Blob([candidate]).size;
16
+ }
@@ -1,4 +1,5 @@
1
1
  import { relativeNow, ONE_MINUTE, filter, map } from './tools';
2
+ import { setInterval, clearInterval } from './timer';
2
3
  var END_OF_TIMES = Infinity;
3
4
  export var CLEAR_OLD_CONTEXTS_INTERVAL = ONE_MINUTE;
4
5
  export function ContextHistory(expireDelay) {
@@ -1,5 +1,6 @@
1
1
  import { ErrorSource } from './errorTools';
2
2
  import { clocksNow, ONE_MINUTE } from './tools';
3
+ import { setTimeout } from './timer';
3
4
  export function createEventRateLimiter(eventType, limit, onLimitReached) {
4
5
  var eventCount = 0;
5
6
  var allowNextEvent = false;
@@ -1,4 +1,5 @@
1
- import { each, noop, jsonStringify } from './tools';
1
+ import { each, noop } from './tools';
2
+ import { jsonStringify } from '../helper/serialisation/jsonStringify';
2
3
  import { computeStackTrace } from '../tracekit';
3
4
  export var ErrorSource = {
4
5
  AGENT: 'agent',
@@ -1,5 +1,5 @@
1
1
  import { noop } from './tools';
2
- import { getZoneJsOriginalValue } from './getZoneJsOriginalValue';
2
+ import { setTimeout } from './timer';
3
3
  export function instrumentMethod(object, method, instrumentationFactory) {
4
4
  var original = object[method];
5
5
  var instrumentation = instrumentationFactory(original);
@@ -57,8 +57,6 @@ export function instrumentSetter(object, property, after) {
57
57
  // component, see issue RUMF-1443
58
58
 
59
59
 
60
- var setTimeout = getZoneJsOriginalValue(window, 'setTimeout');
61
-
62
60
  var instrumentation = function instrumentation(thisObject, value) {
63
61
  // put hooked setter into event loop to avoid of set latency
64
62
  setTimeout(function () {
@@ -0,0 +1,70 @@
1
+ import { computeBytesCount } from '../byteUtils';
2
+ import { deepClone, throttle } from '../tools';
3
+ import { jsonStringify } from './jsonStringify';
4
+ import { warnIfCustomerDataLimitReached } from './heavyCustomerDataWarning';
5
+ export var BYTES_COMPUTATION_THROTTLING_DELAY = 200;
6
+ export function createContextManager(customerDataType, computeBytesCountImpl) {
7
+ if (typeof computeBytesCountImpl === 'undefined') {
8
+ computeBytesCountImpl = computeBytesCount;
9
+ }
10
+
11
+ var context = {};
12
+ var bytesCountCache;
13
+ var alreadyWarned = false; // Throttle the bytes computation to minimize the impact on performance.
14
+ // Especially useful if the user call context APIs synchronously multiple times in a row
15
+
16
+ var computeBytesCountThrottled = throttle(function (context) {
17
+ bytesCountCache = computeBytesCountImpl(jsonStringify(context));
18
+
19
+ if (!alreadyWarned) {
20
+ alreadyWarned = warnIfCustomerDataLimitReached(bytesCountCache, customerDataType);
21
+ }
22
+ }, BYTES_COMPUTATION_THROTTLING_DELAY).throttled;
23
+ return {
24
+ getBytesCount: function getBytesCount() {
25
+ return bytesCountCache;
26
+ },
27
+
28
+ /** @deprecated use getContext instead */
29
+ get: function get() {
30
+ return context;
31
+ },
32
+
33
+ /** @deprecated use setContextProperty instead */
34
+ add: function add(key, value) {
35
+ context[key] = value;
36
+ computeBytesCountThrottled(context);
37
+ },
38
+
39
+ /** @deprecated renamed to removeContextProperty */
40
+ remove: function remove(key) {
41
+ delete context[key];
42
+ computeBytesCountThrottled(context);
43
+ },
44
+
45
+ /** @deprecated use setContext instead */
46
+ set: function set(newContext) {
47
+ context = newContext;
48
+ computeBytesCountThrottled(context);
49
+ },
50
+ getContext: function getContext() {
51
+ return deepClone(context);
52
+ },
53
+ setContext: function setContext(newContext) {
54
+ context = deepClone(newContext);
55
+ computeBytesCountThrottled(context);
56
+ },
57
+ setContextProperty: function setContextProperty(key, property) {
58
+ context[key] = deepClone(property);
59
+ computeBytesCountThrottled(context);
60
+ },
61
+ removeContextProperty: function removeContextProperty(key) {
62
+ delete context[key];
63
+ computeBytesCountThrottled(context);
64
+ },
65
+ clearContext: function clearContext() {
66
+ context = {};
67
+ bytesCountCache = 0;
68
+ }
69
+ };
70
+ }
@@ -0,0 +1,20 @@
1
+ import { ONE_KIBI_BYTE } from '../byteUtils';
2
+ import { display } from '../display'; // RUM and logs batch bytes limit is 16KB
3
+ // ensure that we leave room for other event attributes and maintain a decent amount of event per batch
4
+ // (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB
5
+
6
+ export var CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE;
7
+ export var CustomerDataType = {
8
+ FeatureFlag: 'feature flag evaluation',
9
+ User: 'user',
10
+ GlobalContext: 'global context',
11
+ LoggerContext: 'logger context'
12
+ };
13
+ export function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {
14
+ if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) {
15
+ display.warn('The ' + customerDataType + 'data is over ' + CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE + " KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.");
16
+ return true;
17
+ }
18
+
19
+ return false;
20
+ }
@@ -0,0 +1,46 @@
1
+ import { noop } from '../tools';
2
+ /**
3
+ * Custom implementation of JSON.stringify that ignores some toJSON methods. We need to do that
4
+ * because some sites badly override toJSON on certain objects. Removing all toJSON methods from
5
+ * nested values would be too costly, so we just detach them from the root value, and native classes
6
+ * used to build JSON values (Array and Object).
7
+ *
8
+ * Note: this still assumes that JSON.stringify is correct.
9
+ */
10
+
11
+ export function jsonStringify(value, replacer, space) {
12
+ if (typeof value !== 'object' || value === null) {
13
+ return JSON.stringify(value);
14
+ } // Note: The order matter here. We need to detach toJSON methods on parent classes before their
15
+ // subclasses.
16
+
17
+
18
+ var restoreObjectPrototypeToJson = detachToJsonMethod(Object.prototype);
19
+ var restoreArrayPrototypeToJson = detachToJsonMethod(Array.prototype);
20
+ var restoreValuePrototypeToJson = detachToJsonMethod(Object.getPrototypeOf(value));
21
+ var restoreValueToJson = detachToJsonMethod(value);
22
+
23
+ try {
24
+ return JSON.stringify(value, replacer, space);
25
+ } catch (_unused) {
26
+ return '<error: unable to serialize object>';
27
+ } finally {
28
+ restoreObjectPrototypeToJson();
29
+ restoreArrayPrototypeToJson();
30
+ restoreValuePrototypeToJson();
31
+ restoreValueToJson();
32
+ }
33
+ }
34
+ export function detachToJsonMethod(value) {
35
+ var object = value;
36
+ var objectToJson = object.toJSON;
37
+
38
+ if (objectToJson) {
39
+ delete object.toJSON;
40
+ return () => {
41
+ object.toJSON = objectToJson;
42
+ };
43
+ }
44
+
45
+ return noop;
46
+ }
@@ -0,0 +1,33 @@
1
+ import { jsonStringify } from './jsonStringify';
2
+ import { isString } from '../tools';
3
+ export function escapeRowData(str) {
4
+ if (typeof str === 'object' && str) {
5
+ str = jsonStringify(str);
6
+ } else if (!isString(str)) {
7
+ return str;
8
+ }
9
+
10
+ var reg = /[\s=,"]/g;
11
+ return String(str).replace(reg, function (word) {
12
+ return '\\' + word;
13
+ });
14
+ }
15
+ export function escapeJsonValue(value) {
16
+ if (isString(value)) {
17
+ return value;
18
+ } else {
19
+ return jsonStringify(value);
20
+ }
21
+ }
22
+ export function escapeFieldValueStr(str) {
23
+ return '"' + str.replace(/\\/g, '\\\\').replace(/[\\]*"/g, '"').replace(/"/g, '\\"') + '"';
24
+ }
25
+ export function escapeRowField(value) {
26
+ if (typeof value === 'object' && value) {
27
+ return escapeFieldValueStr(jsonStringify(value));
28
+ } else if (isString(value)) {
29
+ return escapeFieldValueStr(value);
30
+ } else {
31
+ return value;
32
+ }
33
+ }
@@ -0,0 +1,14 @@
1
+ import { getZoneJsOriginalValue } from './getZoneJsOriginalValue';
2
+ import { getGlobalObject } from '../init';
3
+ export function setTimeout(callback, delay) {
4
+ return getZoneJsOriginalValue(getGlobalObject(), 'setTimeout')(callback, delay);
5
+ }
6
+ export function clearTimeout(timeoutId) {
7
+ getZoneJsOriginalValue(getGlobalObject(), 'clearTimeout')(timeoutId);
8
+ }
9
+ export function setInterval(callback, delay) {
10
+ return getZoneJsOriginalValue(window, 'setInterval')(callback, delay);
11
+ }
12
+ export function clearInterval(timeoutId) {
13
+ getZoneJsOriginalValue(window, 'clearInterval')(timeoutId);
14
+ }
@@ -1,5 +1,5 @@
1
1
  import { DOM_EVENT } from './enums';
2
- import { getZoneJsOriginalValue } from './getZoneJsOriginalValue';
2
+ import { setTimeout, clearTimeout } from './timer';
3
3
  var ArrayProto = Array.prototype;
4
4
  var FuncProto = Function.prototype;
5
5
  var ObjProto = Object.prototype;
@@ -749,121 +749,6 @@ export function elementMatches(element, selector) {
749
749
 
750
750
  return false;
751
751
  }
752
- export var addEvent = function addEvent() {
753
- function fixEvent(event) {
754
- if (event) {
755
- event.preventDefault = fixEvent.preventDefault;
756
- event.stopPropagation = fixEvent.stopPropagation;
757
- event._getPath = fixEvent._getPath;
758
- }
759
-
760
- return event;
761
- }
762
-
763
- fixEvent._getPath = function () {
764
- var ev = this;
765
-
766
- var polyfill = function polyfill() {
767
- try {
768
- var element = ev.target;
769
- var pathArr = [element];
770
-
771
- if (element === null || element.parentElement === null) {
772
- return [];
773
- }
774
-
775
- while (element.parentElement !== null) {
776
- element = element.parentElement;
777
- pathArr.unshift(element);
778
- }
779
-
780
- return pathArr;
781
- } catch (error) {
782
- return [];
783
- }
784
- };
785
-
786
- return this.path || this.composedPath() && this.composedPath() || polyfill();
787
- };
788
-
789
- fixEvent.preventDefault = function () {
790
- this.returnValue = false;
791
- };
792
-
793
- fixEvent.stopPropagation = function () {
794
- this.cancelBubble = true;
795
- };
796
-
797
- var register_event = function register_event(element, type, handle) {
798
- if (element && element.addEventListener) {
799
- element.addEventListener(type, function (e) {
800
- e._getPath = fixEvent._getPath;
801
- handler.call(this, e);
802
- }, false);
803
- } else {
804
- var ontype = 'on' + type;
805
- var old_handler = element[ontype];
806
- element[ontype] = makeHandler(element, handler, old_handler);
807
- }
808
- };
809
-
810
- function makeHandler(element, new_handler, old_handlers) {
811
- var handler = function handler(event) {
812
- event = event || fixEvent(window.event);
813
-
814
- if (!event) {
815
- return undefined;
816
- }
817
-
818
- event.target = event.srcElement;
819
- var ret = true;
820
- var old_result, new_result;
821
-
822
- if (typeof old_handlers === 'function') {
823
- old_result = old_handlers(event);
824
- }
825
-
826
- new_result = new_handler.call(element, event);
827
-
828
- if (false === old_result || false === new_result) {
829
- ret = false;
830
- }
831
-
832
- return ret;
833
- };
834
-
835
- return handler;
836
- }
837
-
838
- register_event.apply(null, arguments);
839
- };
840
- export var addHashEvent = function addHashEvent(callback) {
841
- var hashEvent = 'pushState' in window.history ? 'popstate' : 'hashchange';
842
- addEvent(window, hashEvent, callback);
843
- };
844
- export var addSinglePageEvent = function addSinglePageEvent(callback) {
845
- var current_url = location.href;
846
- var historyPushState = window.history.pushState;
847
- var historyReplaceState = window.history.replaceState;
848
-
849
- window.history.pushState = function () {
850
- historyPushState.apply(window.history, arguments);
851
- callback(current_url);
852
- current_url = location.href;
853
- };
854
-
855
- window.history.replaceState = function () {
856
- historyReplaceState.apply(window.history, arguments);
857
- callback(current_url);
858
- current_url = location.href;
859
- };
860
-
861
- var singlePageEvent = historyPushState ? 'popstate' : 'hashchange';
862
- addEvent(window, singlePageEvent, function () {
863
- callback(current_url);
864
- current_url = location.href;
865
- });
866
- };
867
752
  export var cookie = {
868
753
  get: function get(name) {
869
754
  var nameEQ = name + '=';
@@ -1510,63 +1395,12 @@ export var getReferrer = function getReferrer() {
1510
1395
  export var typeDecide = function typeDecide(o, type) {
1511
1396
  return toString.call(o) === '[object ' + type + ']';
1512
1397
  };
1513
- export function jsonStringify(value, replacer, space) {
1514
- if (value === null || value === undefined) {
1515
- return JSON.stringify(value);
1516
- }
1517
-
1518
- var originalToJSON = [false, undefined];
1519
-
1520
- if (hasToJSON(value)) {
1521
- // We need to add a flag and not rely on the truthiness of value.toJSON
1522
- // because it can be set but undefined and that's actually significant.
1523
- originalToJSON = [true, value.toJSON];
1524
- delete value.toJSON;
1525
- }
1526
-
1527
- var originalProtoToJSON = [false, undefined];
1528
- var prototype;
1529
-
1530
- if (typeof value === 'object') {
1531
- prototype = Object.getPrototypeOf(value);
1532
-
1533
- if (hasToJSON(prototype)) {
1534
- originalProtoToJSON = [true, prototype.toJSON];
1535
- delete prototype.toJSON;
1536
- }
1537
- }
1538
-
1539
- var result;
1540
-
1541
- try {
1542
- result = JSON.stringify(value, undefined, space);
1543
- } catch (e) {
1544
- result = '<error: unable to serialize object>';
1545
- } finally {
1546
- if (originalToJSON[0]) {
1547
- value.toJSON = originalToJSON[1];
1548
- }
1549
-
1550
- if (originalProtoToJSON[0]) {
1551
- prototype.toJSON = originalProtoToJSON[1];
1552
- }
1553
- }
1554
-
1555
- return result;
1556
- }
1557
-
1558
- function hasToJSON(value) {
1559
- return typeof value === 'object' && value !== null && value.hasOwnProperty('toJSON');
1560
- }
1561
-
1562
1398
  export function noop() {}
1563
1399
  export var ONE_SECOND = 1000;
1564
1400
  export var ONE_MINUTE = 60 * ONE_SECOND;
1565
1401
  export var ONE_HOUR = 60 * ONE_MINUTE;
1566
1402
  export var ONE_DAY = 24 * ONE_HOUR;
1567
1403
  export var ONE_YEAR = 365 * ONE_DAY;
1568
- export var ONE_KIBI_BYTE = 1024;
1569
- export var ONE_MEBI_BYTE = 1024 * ONE_KIBI_BYTE;
1570
1404
  /**
1571
1405
  * Return true if the draw is successful
1572
1406
  * @param threshold between 0 and 100
@@ -1710,94 +1544,10 @@ export function safeTruncate(candidate, length) {
1710
1544
 
1711
1545
  return candidate.slice(0, length);
1712
1546
  }
1713
- export function addEventListener(eventTarget, event, listener, options) {
1714
- return addEventListeners(eventTarget, [event], listener, options);
1715
- }
1716
- /**
1717
- * Add event listeners to an event emitter object (Window, Element, mock object...). This provides
1718
- * a few conveniences compared to using `element.addEventListener` directly:
1719
- *
1720
- * * supports IE11 by:
1721
- * * using an option object only if needed
1722
- * * emulating the `once` option
1723
- *
1724
- * * wraps the listener with a `monitor` function
1725
- *
1726
- * * returns a `stop` function to remove the listener
1727
- *
1728
- * * with `once: true`, the listener will be called at most once, even if different events are
1729
- * listened
1730
- */
1731
-
1732
- export function addEventListeners(eventTarget, events, listener, options) {
1733
- var wrappedListener = options && options.once ? function (event) {
1734
- stop();
1735
- listener(event);
1736
- } : listener;
1737
- options = options && options.passive ? {
1738
- capture: options.capture,
1739
- passive: options.passive
1740
- } : options && options.capture;
1741
- var add = getZoneJsOriginalValue(eventTarget, 'addEventListener');
1742
- each(events, function (event) {
1743
- add.call(eventTarget, event, wrappedListener, options);
1744
- });
1745
-
1746
- var stop = function stop() {
1747
- var remove = getZoneJsOriginalValue(eventTarget, 'removeEventListener');
1748
- each(events, function (event) {
1749
- remove.call(eventTarget, event, wrappedListener, options);
1750
- });
1751
- };
1752
-
1753
- return {
1754
- stop: stop
1755
- };
1756
- }
1757
1547
  export function includes(candidate, search) {
1758
1548
  // tslint:disable-next-line: no-unsafe-any
1759
1549
  return candidate.indexOf(search) !== -1;
1760
1550
  }
1761
- export function createContextManager() {
1762
- var context = {};
1763
- return {
1764
- get: function get() {
1765
- return context;
1766
- },
1767
- add: function add(key, value) {
1768
- if (isString(key)) {
1769
- context[key] = value;
1770
- } else {
1771
- console.error('key 需要传递字符串类型');
1772
- }
1773
- },
1774
- remove: function remove(key) {
1775
- delete context[key];
1776
- },
1777
- set: function set(newContext) {
1778
- if (isObject(newContext)) {
1779
- context = newContext;
1780
- } else {
1781
- console.error('content 需要传递对象类型数据');
1782
- }
1783
- },
1784
- getContext: function getContext() {
1785
- return deepClone(context);
1786
- },
1787
- setContext: function setContext(newContext) {
1788
- context = deepClone(newContext);
1789
- },
1790
- setContextProperty: function setContextProperty(key, property) {
1791
- context[key] = deepClone(property);
1792
- },
1793
- removeContextProperty: function removeContextProperty(key) {
1794
- delete context[key];
1795
- },
1796
- clearContext: function clearContext() {
1797
- context = {};
1798
- }
1799
- };
1800
- }
1801
1551
  export function find(array, predicate) {
1802
1552
  for (var i = 0; i < array.length; i += 1) {
1803
1553
  var item = array[i];
@@ -1889,37 +1639,6 @@ export function toSnakeCase(word) {
1889
1639
  return (index !== 0 ? '_' : '') + uppercaseLetter.toLowerCase();
1890
1640
  }).replace(/-/g, '_');
1891
1641
  }
1892
- export function escapeRowData(str) {
1893
- if (typeof str === 'object' && str) {
1894
- str = jsonStringify(str);
1895
- } else if (!isString(str)) {
1896
- return str;
1897
- }
1898
-
1899
- var reg = /[\s=,"]/g;
1900
- return String(str).replace(reg, function (word) {
1901
- return '\\' + word;
1902
- });
1903
- }
1904
- export function escapeJsonValue(value) {
1905
- if (isString(value)) {
1906
- return value;
1907
- } else {
1908
- return jsonStringify(value);
1909
- }
1910
- }
1911
- export function escapeFieldValueStr(str) {
1912
- return '"' + str.replace(/\\/g, '\\\\').replace(/[\\]*"/g, '"').replace(/"/g, '\\"') + '"';
1913
- }
1914
- export function escapeRowField(value) {
1915
- if (typeof value === 'object' && value) {
1916
- return escapeFieldValueStr(jsonStringify(value));
1917
- } else if (isString(value)) {
1918
- return escapeFieldValueStr(value);
1919
- } else {
1920
- return value;
1921
- }
1922
- }
1923
1642
  export function isNullUndefinedDefaultValue(data, defaultValue) {
1924
1643
  if (data !== null && data !== void 0) {
1925
1644
  return data;
@@ -1927,16 +1646,6 @@ export function isNullUndefinedDefaultValue(data, defaultValue) {
1927
1646
  return defaultValue;
1928
1647
  }
1929
1648
  }
1930
- export function runOnReadyState(expectedReadyState, callback) {
1931
- if (document.readyState === expectedReadyState || document.readyState === 'complete') {
1932
- callback();
1933
- } else {
1934
- var eventName = expectedReadyState === 'complete' ? DOM_EVENT.LOAD : DOM_EVENT.DOM_CONTENT_LOADED;
1935
- addEventListener(window, eventName, callback, {
1936
- once: true
1937
- });
1938
- }
1939
- }
1940
1649
  export function requestIdleCallback(callback, opts) {
1941
1650
  // Use 'requestIdleCallback' when available: it will throttle the mutation processing if the
1942
1651
  // browser is busy rendering frames (ex: when frames are below 60fps). When not available, the