@appsurify-testmap/rrweb-snapshot 3.11.0-alpha.1 → 3.12.0-alpha.1

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.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DataURLOptions } from '@appsurify-testmap/rrweb-types';
2
+ import { default as default_2 } from '@appsurify-testmap/rrweb-utils';
2
3
  import { IMirror } from '@appsurify-testmap/rrweb-types';
3
4
  import { serializedElementNodeWithId } from '@appsurify-testmap/rrweb-types';
4
5
  import { serializedNode } from '@appsurify-testmap/rrweb-types';
@@ -76,7 +77,7 @@ export declare function isElement(n: Node): n is Element;
76
77
 
77
78
  export declare function isElementInteractive(n: Node): boolean;
78
79
 
79
- export declare function isElementVisible(el: Element): boolean;
80
+ export declare function isElementVisible(el: Element): ReturnType<typeof default_2.getElementVisibility>;
80
81
 
81
82
  export declare function isExcludeAttribute(name: string, exclude: string | RegExp | undefined): boolean;
82
83
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DataURLOptions } from '@appsurify-testmap/rrweb-types';
2
+ import { default as default_2 } from '@appsurify-testmap/rrweb-utils';
2
3
  import { IMirror } from '@appsurify-testmap/rrweb-types';
3
4
  import { serializedElementNodeWithId } from '@appsurify-testmap/rrweb-types';
4
5
  import { serializedNode } from '@appsurify-testmap/rrweb-types';
@@ -76,7 +77,7 @@ export declare function isElement(n: Node): n is Element;
76
77
 
77
78
  export declare function isElementInteractive(n: Node): boolean;
78
79
 
79
- export declare function isElementVisible(el: Element): boolean;
80
+ export declare function isElementVisible(el: Element): ReturnType<typeof default_2.getElementVisibility>;
80
81
 
81
82
  export declare function isExcludeAttribute(name: string, exclude: string | RegExp | undefined): boolean;
82
83
 
@@ -172,16 +172,30 @@ function describeNode(el) {
172
172
  const classes = el.classList.length ? "." + Array.from(el.classList).join(".") : "";
173
173
  return `${tag}${id}${classes}`;
174
174
  }
175
+ function isAncestorOpacityVisible(el, win) {
176
+ var _a;
177
+ let node2 = el.parentElement;
178
+ while (node2) {
179
+ const s = (_a = win.getComputedStyle) == null ? void 0 : _a.call(win, node2);
180
+ if (s && (parseFloat(s.opacity) || 0) <= 0) {
181
+ return false;
182
+ }
183
+ node2 = node2.parentElement;
184
+ }
185
+ return true;
186
+ }
175
187
  function getElementVisibility(el) {
176
188
  var _a, _b;
177
189
  const win = ((_a = el.ownerDocument) == null ? void 0 : _a.defaultView) ?? window;
178
190
  const rect = el.getBoundingClientRect();
179
191
  const viewportWidth = win.innerWidth || win.document.documentElement.clientWidth || 0;
180
192
  const viewportHeight = win.innerHeight || win.document.documentElement.clientHeight || 0;
181
- const isRectVisible = rect.width > 0 && rect.height > 0 && rect.bottom > 0 && rect.right > 0 && rect.top < viewportHeight && rect.left < viewportWidth;
193
+ const elHasSize = rect.width > 0 && rect.height > 0;
194
+ const isViewportVisible = elHasSize && rect.bottom > 0 && rect.right > 0 && rect.top < viewportHeight && rect.left < viewportWidth;
182
195
  const style = (_b = win.getComputedStyle) == null ? void 0 : _b.call(win, el);
183
- const isStyleVisible = !!style && style.display !== "none" && style.visibility !== "hidden" && (parseFloat(style.opacity) || 0) > 0;
184
- const isVisible = isStyleVisible && isRectVisible;
196
+ const isOwnStyleVisible = !!style && style.display !== "none" && style.visibility !== "hidden" && (parseFloat(style.opacity) || 0) > 0;
197
+ const isCSSVisible = isOwnStyleVisible && isAncestorOpacityVisible(el, win);
198
+ const isVisible = isCSSVisible && isViewportVisible;
185
199
  let ratio = 0;
186
200
  if (isVisible) {
187
201
  const xOverlap = Math.max(
@@ -198,6 +212,9 @@ function getElementVisibility(el) {
198
212
  }
199
213
  return {
200
214
  isVisible,
215
+ isCSSVisible,
216
+ isViewportVisible,
217
+ hasSize: elHasSize,
201
218
  ratio
202
219
  };
203
220
  }
@@ -649,19 +666,18 @@ function isTextVisible(n) {
649
666
  var _a;
650
667
  const parent = index.parentNode(n);
651
668
  const parentElement2 = parent && parent;
652
- if (!parentElement2) {
669
+ if (!parentElement2 || parentElement2.nodeType !== Node.ELEMENT_NODE) {
653
670
  return false;
654
671
  }
655
- const isParentVisible = isElementVisible(parentElement2);
656
- if (!isParentVisible) {
672
+ const parentVis = isElementVisible(parentElement2);
673
+ if (!parentVis.isVisible) {
657
674
  return false;
658
675
  }
659
676
  const textContent2 = (_a = n.textContent) == null ? void 0 : _a.trim();
660
677
  return textContent2 !== "";
661
678
  }
662
679
  function isElementVisible(el) {
663
- const visibility = index.getElementVisibility(el);
664
- return visibility.isVisible;
680
+ return index.getElementVisibility(el);
665
681
  }
666
682
  const interactiveEvents = [
667
683
  "change",
@@ -3091,7 +3107,11 @@ function serializeNodeWithId(n, options) {
3091
3107
  serializedNode.isVisible = isTextVisible(n);
3092
3108
  }
3093
3109
  if (n.nodeType === Node.ELEMENT_NODE) {
3094
- serializedNode.isVisible = isElementVisible(n);
3110
+ const vis = isElementVisible(n);
3111
+ serializedNode.isVisible = vis.isVisible;
3112
+ serializedNode.isCSSVisible = vis.isCSSVisible;
3113
+ serializedNode.isViewportVisible = vis.isViewportVisible;
3114
+ serializedNode.hasSize = vis.hasSize;
3095
3115
  serializedNode.isInteractive = isElementInteractive(n);
3096
3116
  }
3097
3117
  }