@pendo/agent 2.275.1 → 2.277.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/README.md CHANGED
@@ -45,7 +45,7 @@ The object returned by calling `initialize` is the same as a snippet install of
45
45
  | key | required? | type | description |
46
46
  | --- | --------- | ---- | ---------- |
47
47
  | apiKey | required | string | Your specific application `apiKey` can be found by going to the application details page in the Pendo App for your application. It will be a 32-digit code that identifies that application and connects it to Pendo. |
48
- | env | required | string | The environment that your Pendo subscription resides in. `io` is the default US environment and environments other than that can be found in the url that you use to access Pendo (e.g. app.`eu`.pendo.io). One of: ['io', 'eu', 'jpn', 'us1', 'au']. |
48
+ | env | required | string | The environment that your Pendo subscription resides in. `io` is the default US environment and environments other than that can be found in the url that you use to access Pendo (e.g. app.`eu`.pendo.io). One of: ['io', 'eu', 'jpn', 'us1', 'au', 'gov']. |
49
49
  | visitor | optional | object | The visitor information for the current user of your application. This includes the `id` and any other metadata you want attached to the visitor. If not provided the visitor will be treated as an anonymous visitor. |
50
50
  | account | optional | object | The account information for the current user of your application if applicable. If not provided the visitor will not be assigned to an account. |
51
51
  | globalKey | optional | string | The key where you would like the global `pendo` object to be stored after initialization. By default this will be stored on `window.pendo` but this allows it to change to a different name if desired. |
package/dist/dom.esm.js CHANGED
@@ -7094,7 +7094,11 @@ var sniffer = {
7094
7094
 
7095
7095
  // other node types can be read about here:
7096
7096
  // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
7097
+ var TEXT = 3;
7097
7098
  var ELEMENT = 1;
7099
+ var DOCUMENT = 9;
7100
+ var DOCUMENT_FRAGMENT = 11;
7101
+ var CDATA_SECTION = 4;
7098
7102
  function isElementNode(node) {
7099
7103
  return node && node.nodeType === ELEMENT;
7100
7104
  }
@@ -7224,7 +7228,7 @@ function getScreenPosition(element) {
7224
7228
  };
7225
7229
  }
7226
7230
 
7227
- var VERSION = '2.275.1_';
7231
+ var VERSION = '2.277.0_';
7228
7232
  function isExtensionAgent() {
7229
7233
  var installType = getPendoConfigValue('installType') || getPendoConfigFromEnclosingScope().installType;
7230
7234
  return installType === EXTENSION_INSTALL_TYPE;
@@ -8635,14 +8639,15 @@ function roundOffsetPosition(position) {
8635
8639
  });
8636
8640
  return position;
8637
8641
  }
8638
- function getOffsetPosition(element) {
8642
+ function getOffsetPosition(element, _win) {
8643
+ if (_win === void 0) { _win = window; }
8639
8644
  if (isPositionFixed(element)) {
8640
8645
  var fixedPosition = getScreenPosition(element);
8641
8646
  fixedPosition.fixed = true;
8642
8647
  return roundOffsetPosition(fixedPosition);
8643
8648
  }
8644
8649
  else {
8645
- var absolutePosition = getAbsolutePosition(element, getBody());
8650
+ var absolutePosition = getAbsolutePosition(element, getBody(_win.document), _win);
8646
8651
  return roundOffsetPosition(absolutePosition);
8647
8652
  }
8648
8653
  }
@@ -9594,6 +9599,233 @@ DomQuery.$ = {
9594
9599
  }
9595
9600
  };
9596
9601
 
9602
+ /**
9603
+ * Abstraction on top of Mutation Observer that has a naive polyfill to use setTimeout and look
9604
+ * every half second for changes.
9605
+ *
9606
+ * This observer only attempts to verify changes to `isInDocument` status for all "observed" elements.
9607
+ * The side effect of changing status is left to the element and any code owning said element to handle.
9608
+ */
9609
+ var DomObserver = /** @class */ (function () {
9610
+ function DomObserver(container, config) {
9611
+ if (container === void 0) { container = getBody(); }
9612
+ if (config === void 0) { config = { 'attributes': true, 'childList': true, 'subtree': true }; }
9613
+ var _this = this;
9614
+ this.listeners = [];
9615
+ this._teardown = function () { };
9616
+ if (sniffer.MutationObserver) {
9617
+ var MutationObserver_1 = getZoneSafeMethod('MutationObserver');
9618
+ var observer_1 = new MutationObserver_1(function (mutationList, observer) {
9619
+ _this.signal();
9620
+ });
9621
+ observer_1.observe(container, config);
9622
+ this._teardown = function () { return observer_1.disconnect; };
9623
+ }
9624
+ else {
9625
+ var handle_1 = setTimeout$1(function () {
9626
+ _this.signal();
9627
+ }, 500);
9628
+ this._teardown = function () {
9629
+ clearTimeout(handle_1);
9630
+ };
9631
+ }
9632
+ }
9633
+ DomObserver.prototype.signal = function () {
9634
+ _.each(this.listeners, function (el) {
9635
+ el.get();
9636
+ });
9637
+ };
9638
+ DomObserver.prototype.addObservers = function () {
9639
+ var elements = [];
9640
+ for (var _i = 0; _i < arguments.length; _i++) {
9641
+ elements[_i] = arguments[_i];
9642
+ }
9643
+ this.listeners = [].concat(this.listeners, elements);
9644
+ };
9645
+ DomObserver.prototype.teardown = function () {
9646
+ this._teardown();
9647
+ };
9648
+ return DomObserver;
9649
+ }());
9650
+
9651
+ function WeakRefFactory() {
9652
+ function WeakRef(obj) {
9653
+ this._object = obj;
9654
+ }
9655
+
9656
+ WeakRef.prototype.deref = function() {
9657
+ return this._object;
9658
+ };
9659
+
9660
+ return WeakRef;
9661
+ }
9662
+
9663
+ var WeakRef = (function(global, factory) {
9664
+ var nativeWeakRef = global.WeakRef;
9665
+ if (typeof nativeWeakRef !== 'function' || !/native/.test(nativeWeakRef)) {
9666
+ return factory();
9667
+ }
9668
+
9669
+ return nativeWeakRef;
9670
+ })(window, WeakRefFactory);
9671
+
9672
+ var trimString = function (str, limit) {
9673
+ var len = str.length;
9674
+ if (len <= limit)
9675
+ return str;
9676
+ return trimSurrogate(str.substring(0, limit));
9677
+ };
9678
+ function getTextValue(elem, limit) {
9679
+ if (elem.tagName && ['textarea', 'input'].indexOf(elem.tagName.toLowerCase()) > -1) {
9680
+ return trimString(elem.value, limit);
9681
+ }
9682
+ return getText(elem, limit);
9683
+ }
9684
+ function getText(elem, limit) {
9685
+ if (limit === void 0) { limit = 128; }
9686
+ var ret = '';
9687
+ var nodeType = elem.nodeType;
9688
+ var sub;
9689
+ if (nodeType === TEXT || nodeType === CDATA_SECTION) {
9690
+ return elem.nodeValue;
9691
+ }
9692
+ else if (!isElemBlacklisted(elem) &&
9693
+ (nodeType === ELEMENT ||
9694
+ nodeType === DOCUMENT ||
9695
+ nodeType === DOCUMENT_FRAGMENT)) {
9696
+ // Traverse its children
9697
+ if (!elem.childNodes)
9698
+ return ret;
9699
+ for (var i = 0; i < elem.childNodes.length; ++i) {
9700
+ var child = elem.childNodes[i];
9701
+ sub = getText(child, limit - ret.length);
9702
+ if ((ret + sub).length >= limit) {
9703
+ return ret + trimSurrogate(sub.substring(0, limit - ret.length));
9704
+ }
9705
+ ret += sub;
9706
+ }
9707
+ }
9708
+ return ret;
9709
+ }
9710
+ function isElemBlacklisted(elem) {
9711
+ return !elem.tagName || elem.tagName.toLowerCase() == 'textarea';
9712
+ }
9713
+ /**
9714
+ * Determine if the supplied {codepoint} falls within the "high surrogate" range
9715
+ * of unicode characters.
9716
+ *
9717
+ * @access private
9718
+ * @param {number} codepoint
9719
+ * @returns {boolean}
9720
+ * @see https://en.wikipedia.org/wiki/UTF-16#U.2BD800_to_U.2BDFFF
9721
+ */
9722
+ function isHighSurrogate(codepoint) {
9723
+ return (0xD800 <= codepoint && codepoint <= 0xDBFF);
9724
+ }
9725
+ /**
9726
+ * Determine if the supplied {codepoint} falls within the "low surrogate" range
9727
+ * of unicode characters.
9728
+ *
9729
+ * @access private
9730
+ * @param {number} codepoint
9731
+ * @returns {boolean}
9732
+ * @see https://en.wikipedia.org/wiki/UTF-16#U.2BD800_to_U.2BDFFF
9733
+ */
9734
+ function isLowSurrogate(codepoint) {
9735
+ return (0xDC00 <= codepoint && codepoint <= 0xDFFF);
9736
+ }
9737
+ /**
9738
+ * Remove "high surrogate" or unmatched "low surrogate" characters from the end
9739
+ * of {s}, indicating a broken unicode glyph. This happens when we truncate the
9740
+ * text of a node in {getText} that ends with a double-byte-encoded unicode glyph
9741
+ * such as emoji.
9742
+ *
9743
+ * @access private
9744
+ * @see https://github.com/pendo-io/pendo-client/pull/12
9745
+ * @param {string} s
9746
+ * @returns {string} s if no trailing surrogates, s-1 otherwise
9747
+ */
9748
+ function trimSurrogate(s) {
9749
+ // If the string is empty, it's definitely _not_ a "lonely surrogate"...
9750
+ if (s.length < 1)
9751
+ return s;
9752
+ var last = s.slice(-1).charCodeAt(0);
9753
+ // We're only interested in the `last` character...
9754
+ if (!isHighSurrogate(last) && !isLowSurrogate(last))
9755
+ return s;
9756
+ // If the string is only 1 character, that surrogate is definitely "lonely"...
9757
+ if (s.length === 1)
9758
+ return s.slice(0, -1);
9759
+ // All "lonely high surrogates" shall be eradicated...
9760
+ if (isHighSurrogate(last))
9761
+ return s.slice(0, -1);
9762
+ // Not sure how "lonely low surrogate" could happen, but let's check!
9763
+ if (isLowSurrogate(last)) {
9764
+ // Per above, the `last` character isn't the _only_ character...
9765
+ var prev = s.slice(-2).charCodeAt(0);
9766
+ // And if the `prev` character isn't a "high surrogate", that "low surrogate" is lonely.
9767
+ if (!isHighSurrogate(prev))
9768
+ return s.slice(0, -1);
9769
+ }
9770
+ return s; // otherwise leave it alone
9771
+ }
9772
+
9773
+ var ElementGetter = /** @class */ (function () {
9774
+ function ElementGetter(cssSelector) {
9775
+ this.listeners = {}; // callbacks to be called when an event of type occurs
9776
+ this.events = []; // event types this element listens for
9777
+ this.cssSelector = cssSelector;
9778
+ }
9779
+ ElementGetter.prototype.get = function () {
9780
+ var _this = this;
9781
+ var el = this.elRef && this.elRef.deref();
9782
+ var isInDoc = isInDocument(el); // is this safe to call if el is null?
9783
+ if (el && isInDoc)
9784
+ return el;
9785
+ if (el && !isInDoc) {
9786
+ return undefined;
9787
+ }
9788
+ el = dom(this.cssSelector)[0];
9789
+ if (!el) {
9790
+ return undefined;
9791
+ }
9792
+ _.each(this.events, function (evtType) {
9793
+ el.addEventListener(evtType, function (e) { return _this.onEvent(e); });
9794
+ });
9795
+ this.elRef = new WeakRef(el);
9796
+ return el;
9797
+ };
9798
+ ElementGetter.prototype.getText = function (limit) {
9799
+ if (limit === void 0) { limit = 1024; }
9800
+ // XXX not sure about size limit
9801
+ return getTextValue(this.get(), limit);
9802
+ };
9803
+ ElementGetter.prototype.addEventListener = function (event, callback) {
9804
+ var _this = this;
9805
+ var el = this.get();
9806
+ if (this.events.indexOf(event) < 0) {
9807
+ this.events.push(event);
9808
+ if (el) {
9809
+ el.addEventListener(event, function (e) { return _this.onEvent(e); });
9810
+ }
9811
+ }
9812
+ this.listeners[event] = this.listeners[event]
9813
+ ? this.listeners[event].push(callback) : [].concat(callback);
9814
+ };
9815
+ ElementGetter.prototype.onEvent = function (evt) {
9816
+ var type = evt.type;
9817
+ _.each(this.listeners[type], function (cb) { return cb(evt); });
9818
+ };
9819
+ ElementGetter.prototype.teardown = function () {
9820
+ var _this = this;
9821
+ var el = this.get();
9822
+ if (el) {
9823
+ _.each(this.events, function (evtType) { return el.removeEventListener(evtType, _this.onEvent); });
9824
+ }
9825
+ };
9826
+ return ElementGetter;
9827
+ }());
9828
+
9597
9829
  _.extend(dom, {
9598
9830
  'data': DomData$1,
9599
9831
  'event': DomEvent,
@@ -9608,6 +9840,8 @@ _.extend(dom, {
9608
9840
  'intersectRect': intersectRect,
9609
9841
  'getScrollParent': getScrollParent,
9610
9842
  'isElementVisible': isElementVisible,
9843
+ 'Observer': DomObserver,
9844
+ 'Element': ElementGetter,
9611
9845
  'scrollIntoView': scrollIntoView,
9612
9846
  'getRootNode': getRootNode
9613
9847
  });