@atlaskit/react-ufo 3.4.0 → 3.4.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/additional-payload/utils/lighthouse-metrics/utils/observer/index.js +8 -2
  3. package/dist/cjs/create-payload/index.js +136 -76
  4. package/dist/cjs/segment/segment.js +29 -4
  5. package/dist/cjs/vc/vc-observer/index.js +71 -46
  6. package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/index.js +18 -11
  7. package/dist/cjs/vc/vc-observer-new/get-element-name.js +52 -65
  8. package/dist/cjs/vc/vc-observer-new/get-unique-element-name.js +80 -0
  9. package/dist/cjs/vc/vc-observer-new/metric-calculator/fy25_03/index.js +7 -2
  10. package/dist/cjs/vc/vc-observer-new/metric-calculator/percentile-calc/canvas-heatmap/canvas-pixel.js +6 -4
  11. package/dist/cjs/vc/vc-observer-new/viewport-observer/index.js +17 -9
  12. package/dist/es2019/additional-payload/utils/lighthouse-metrics/utils/observer/index.js +8 -2
  13. package/dist/es2019/create-payload/index.js +39 -3
  14. package/dist/es2019/segment/segment.js +29 -3
  15. package/dist/es2019/vc/vc-observer/index.js +39 -12
  16. package/dist/es2019/vc/vc-observer/observers/ssr-placeholders/index.js +14 -7
  17. package/dist/es2019/vc/vc-observer-new/get-element-name.js +51 -65
  18. package/dist/es2019/vc/vc-observer-new/get-unique-element-name.js +74 -0
  19. package/dist/es2019/vc/vc-observer-new/metric-calculator/fy25_03/index.js +6 -1
  20. package/dist/es2019/vc/vc-observer-new/metric-calculator/percentile-calc/canvas-heatmap/canvas-pixel.js +6 -4
  21. package/dist/es2019/vc/vc-observer-new/viewport-observer/index.js +17 -9
  22. package/dist/esm/additional-payload/utils/lighthouse-metrics/utils/observer/index.js +8 -2
  23. package/dist/esm/create-payload/index.js +136 -76
  24. package/dist/esm/segment/segment.js +29 -4
  25. package/dist/esm/vc/vc-observer/index.js +71 -46
  26. package/dist/esm/vc/vc-observer/observers/ssr-placeholders/index.js +18 -11
  27. package/dist/esm/vc/vc-observer-new/get-element-name.js +52 -65
  28. package/dist/esm/vc/vc-observer-new/get-unique-element-name.js +74 -0
  29. package/dist/esm/vc/vc-observer-new/metric-calculator/fy25_03/index.js +6 -1
  30. package/dist/esm/vc/vc-observer-new/metric-calculator/percentile-calc/canvas-heatmap/canvas-pixel.js +6 -4
  31. package/dist/esm/vc/vc-observer-new/viewport-observer/index.js +17 -9
  32. package/dist/types/assets/utils.d.ts +1 -1
  33. package/dist/types/interaction-context/index.d.ts +2 -0
  34. package/dist/types/segment/segment.d.ts +2 -1
  35. package/dist/types/vc/vc-observer-new/get-unique-element-name.d.ts +8 -0
  36. package/dist/types/vc/vc-observer-new/metric-calculator/fy25_03/index.d.ts +1 -0
  37. package/dist/types-ts4.5/assets/utils.d.ts +1 -1
  38. package/dist/types-ts4.5/interaction-context/index.d.ts +2 -0
  39. package/dist/types-ts4.5/segment/segment.d.ts +2 -1
  40. package/dist/types-ts4.5/vc/vc-observer-new/get-unique-element-name.d.ts +8 -0
  41. package/dist/types-ts4.5/vc/vc-observer-new/metric-calculator/fy25_03/index.d.ts +1 -0
  42. package/package.json +7 -1
@@ -103,7 +103,7 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
103
103
  });
104
104
  (0, _defineProperty2.default)(this, "getVCResult", /*#__PURE__*/function () {
105
105
  var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref3) {
106
- var start, stop, tti, prefix, ssr, vc, isEventAborted, startTime, fullPrefix, rawData, abortReason, abortReasonInfo, heatmap, heatmapNext, outOfBoundaryInfo, totalTime, componentsLog, viewport, devToolsEnabled, ratios, multiHeatmap, _VCObserver$calculate, VC, VCBox, VCEntries, totalPainted, _componentsLog, vcNext, outOfBoundary, stopTime, isMultiHeatmapEnabled, revisionsData, isCalcSpeedIndexEnabled, speedIndex;
106
+ var start, stop, tti, prefix, ssr, vc, isEventAborted, startTime, fullPrefix, rawData, abortReason, abortReasonInfo, heatmap, heatmapNext, outOfBoundaryInfo, totalTime, componentsLog, viewport, devToolsEnabled, ratios, multiHeatmap, _VCObserver$calculate, VC, VCBox, VCEntries, totalPainted, _componentsLog, vcNext, outOfBoundary, stopTime, isVCClean, isMultiHeatmapEnabled, revisionsData, isCalcSpeedIndexEnabled, speedIndex;
107
107
  return _regenerator.default.wrap(function _callee$(_context) {
108
108
  while (1) switch (_context.prev = _context.next) {
109
109
  case 0:
@@ -240,31 +240,54 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
240
240
  } catch (e) {
241
241
  /* do nothing */
242
242
  }
243
+ isVCClean = !abortReasonInfo;
243
244
  isMultiHeatmapEnabled = !(0, _platformFeatureFlags.fg)('platform_ufo_multiheatmap_killswitch');
244
- revisionsData = isMultiHeatmapEnabled && multiHeatmap !== null ? (0, _defineProperty2.default)({}, "".concat(fullPrefix, "vc:rev"), multiHeatmap === null || multiHeatmap === void 0 ? void 0 : multiHeatmap.getPayloadShapedData({
245
+ revisionsData = isMultiHeatmapEnabled ? (0, _platformFeatureFlags.fg)('platform_ufo_vc_observer_new') ? (0, _defineProperty2.default)({}, "".concat(fullPrefix, "vc:rev"), [{
246
+ revision: 'fy25.01',
247
+ clean: isVCClean,
248
+ 'metric:vc90': VC['90'],
249
+ vcDetails: Object.fromEntries(VCObserver.VCParts.map(function (key) {
250
+ var _VCBox$key;
251
+ return [key, {
252
+ t: VC[key],
253
+ e: (_VCBox$key = VCBox[key]) !== null && _VCBox$key !== void 0 ? _VCBox$key : []
254
+ }];
255
+ }))
256
+ }, {
257
+ revision: 'fy25.02',
258
+ clean: isVCClean,
259
+ 'metric:vc90': vcNext.VC['90'],
260
+ vcDetails: Object.fromEntries(VCObserver.VCParts.map(function (key) {
261
+ var _vcNext$VCBox$key;
262
+ return [key, {
263
+ t: vcNext.VC[key],
264
+ e: (_vcNext$VCBox$key = vcNext.VCBox[key]) !== null && _vcNext$VCBox$key !== void 0 ? _vcNext$VCBox$key : []
265
+ }];
266
+ }))
267
+ }]) : multiHeatmap !== null ? (0, _defineProperty2.default)({}, "".concat(fullPrefix, "vc:rev"), multiHeatmap === null || multiHeatmap === void 0 ? void 0 : multiHeatmap.getPayloadShapedData({
245
268
  VCParts: VCObserver.VCParts.map(function (v) {
246
269
  return parseInt(v);
247
270
  }),
248
- VCCalculationMethods: (0, _revisions.getRevisions)().map(function (_ref9) {
249
- var classifier = _ref9.classifier;
271
+ VCCalculationMethods: (0, _revisions.getRevisions)().map(function (_ref10) {
272
+ var classifier = _ref10.classifier;
250
273
  return classifier.VCCalculationMethod;
251
274
  }),
252
- filterComponentsLog: (0, _revisions.getRevisions)().map(function (_ref10) {
253
- var classifier = _ref10.classifier;
275
+ filterComponentsLog: (0, _revisions.getRevisions)().map(function (_ref11) {
276
+ var classifier = _ref11.classifier;
254
277
  return classifier.filterComponentsLog;
255
278
  }),
256
279
  isEventAborted: isEventAborted,
257
280
  interactionStart: start,
258
281
  ttai: stop,
259
282
  ssr: ssr,
260
- clean: !abortReasonInfo
261
- })) : null; // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
283
+ clean: isVCClean
284
+ })) : null : null; // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
262
285
  isCalcSpeedIndexEnabled = (0, _platformFeatureFlags.fg)('ufo-calc-speed-index');
263
286
  speedIndex = (0, _defineProperty2.default)((0, _defineProperty2.default)({}, "ufo:speedIndex", VCEntries.speedIndex), "ufo:next:speedIndex", vcNext.VCEntries.speedIndex);
264
287
  return _context.abrupt("return", _objectSpread(_objectSpread(_objectSpread((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({
265
288
  'metrics:vc': VC
266
- }, "".concat(fullPrefix, "vc:state"), true), "".concat(fullPrefix, "vc:clean"), !abortReasonInfo), "".concat(fullPrefix, "vc:dom"), VCBox), "".concat(fullPrefix, "vc:updates"), VCEntries.rel.slice(0, 50)), "".concat(fullPrefix, "vc:size"), viewport), "".concat(fullPrefix, "vc:time"), Math.round(totalTime + (stopTime - startTime))), "".concat(fullPrefix, "vc:total"), totalPainted), "".concat(fullPrefix, "vc:ratios"), ratios), outOfBoundary), {}, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, "".concat(fullPrefix, "vc:next"), vcNext.VC), "".concat(fullPrefix, "vc:next:updates"), vcNext.VCEntries.rel.slice(0, 50)), "".concat(fullPrefix, "vc:next:dom"), vcNext.VCBox), "".concat(fullPrefix, "vc:ignored"), _this.getIgnoredElements(componentsLog)), revisionsData), isCalcSpeedIndexEnabled ? speedIndex : {}));
267
- case 24:
289
+ }, "".concat(fullPrefix, "vc:state"), true), "".concat(fullPrefix, "vc:clean"), isVCClean), "".concat(fullPrefix, "vc:dom"), VCBox), "".concat(fullPrefix, "vc:updates"), VCEntries.rel.slice(0, 50)), "".concat(fullPrefix, "vc:size"), viewport), "".concat(fullPrefix, "vc:time"), Math.round(totalTime + (stopTime - startTime))), "".concat(fullPrefix, "vc:total"), totalPainted), "".concat(fullPrefix, "vc:ratios"), ratios), outOfBoundary), {}, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, "".concat(fullPrefix, "vc:next"), vcNext.VC), "".concat(fullPrefix, "vc:next:updates"), vcNext.VCEntries.rel.slice(0, 50)), "".concat(fullPrefix, "vc:next:dom"), vcNext.VCBox), "".concat(fullPrefix, "vc:ignored"), _this.getIgnoredElements(componentsLog)), revisionsData), isCalcSpeedIndexEnabled ? speedIndex : {}));
290
+ case 25:
268
291
  case "end":
269
292
  return _context.stop();
270
293
  }
@@ -277,14 +300,16 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
277
300
  (0, _defineProperty2.default)(this, "handleUpdate", function (rawTime, intersectionRect, targetName, element, type, ignoreReason) {
278
301
  _this.measureStart();
279
302
  _this.legacyHandleUpdate(rawTime, intersectionRect, targetName, element, type, ignoreReason);
280
- _this.onViewportChangeDetected({
281
- timestamp: rawTime,
282
- intersectionRect: intersectionRect,
283
- targetName: targetName,
284
- element: element,
285
- type: type,
286
- ignoreReason: ignoreReason
287
- });
303
+ if (!(0, _platformFeatureFlags.fg)('platform_ufo_vc_observer_new')) {
304
+ _this.onViewportChangeDetected({
305
+ timestamp: rawTime,
306
+ intersectionRect: intersectionRect,
307
+ targetName: targetName,
308
+ element: element,
309
+ type: type,
310
+ ignoreReason: ignoreReason
311
+ });
312
+ }
288
313
  _this.measureStop();
289
314
  });
290
315
  (0, _defineProperty2.default)(this, "legacyHandleUpdate", function (rawTime, intersectionRect, targetName, element, type, ignoreReason) {
@@ -309,13 +334,13 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
309
334
  });
310
335
  }
311
336
  });
312
- (0, _defineProperty2.default)(this, "onViewportChangeDetected", function (_ref12) {
313
- var element = _ref12.element,
314
- type = _ref12.type,
315
- ignoreReason = _ref12.ignoreReason,
316
- timestamp = _ref12.timestamp,
317
- targetName = _ref12.targetName,
318
- intersectionRect = _ref12.intersectionRect;
337
+ (0, _defineProperty2.default)(this, "onViewportChangeDetected", function (_ref13) {
338
+ var element = _ref13.element,
339
+ type = _ref13.type,
340
+ ignoreReason = _ref13.ignoreReason,
341
+ timestamp = _ref13.timestamp,
342
+ targetName = _ref13.targetName,
343
+ intersectionRect = _ref13.intersectionRect;
319
344
  if (_this.multiHeatmap === null) {
320
345
  return;
321
346
  }
@@ -397,10 +422,10 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
397
422
  var unbinds = (0, _attachAbortListeners.attachAbortListeners)(window, _this.viewport, _this.abortReasonCallback);
398
423
  if ((_window = window) !== null && _window !== void 0 && _window.__SSR_ABORT_LISTENERS__) {
399
424
  var _window2;
400
- Object.entries(window.__SSR_ABORT_LISTENERS__.aborts).forEach(function (_ref13) {
401
- var _ref14 = (0, _slicedToArray2.default)(_ref13, 2),
402
- key = _ref14[0],
403
- time = _ref14[1];
425
+ Object.entries(window.__SSR_ABORT_LISTENERS__.aborts).forEach(function (_ref14) {
426
+ var _ref15 = (0, _slicedToArray2.default)(_ref14, 2),
427
+ key = _ref15[0],
428
+ time = _ref15[1];
404
429
  if (time) {
405
430
  _this.abortReasonCallback(key, time);
406
431
  }
@@ -433,8 +458,8 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
433
458
  }
434
459
  return (0, _createClass2.default)(VCObserver, [{
435
460
  key: "start",
436
- value: function start(_ref15) {
437
- var startTime = _ref15.startTime;
461
+ value: function start(_ref16) {
462
+ var startTime = _ref16.startTime;
438
463
  this.active = true;
439
464
  if (this.observers.isBrowserSupported()) {
440
465
  this.setViewportSize();
@@ -456,12 +481,12 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
456
481
  }, {
457
482
  key: "getIgnoredElements",
458
483
  value: function getIgnoredElements(componentsLog) {
459
- return Object.values(componentsLog).flat().filter(function (_ref16) {
460
- var ignoreReason = _ref16.ignoreReason;
484
+ return Object.values(componentsLog).flat().filter(function (_ref17) {
485
+ var ignoreReason = _ref17.ignoreReason;
461
486
  return Boolean(ignoreReason);
462
- }).map(function (_ref17) {
463
- var targetName = _ref17.targetName,
464
- ignoreReason = _ref17.ignoreReason;
487
+ }).map(function (_ref18) {
488
+ var targetName = _ref18.targetName,
489
+ ignoreReason = _ref18.ignoreReason;
465
490
  return {
466
491
  targetName: targetName,
467
492
  ignoreReason: ignoreReason
@@ -581,12 +606,12 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
581
606
  }
582
607
  }], [{
583
608
  key: "calculateVC",
584
- value: function calculateVC(_ref18) {
585
- var heatmap = _ref18.heatmap,
586
- _ref18$ssr = _ref18.ssr,
587
- ssr = _ref18$ssr === void 0 ? UNUSED_SECTOR : _ref18$ssr,
588
- componentsLog = _ref18.componentsLog,
589
- viewport = _ref18.viewport;
609
+ value: function calculateVC(_ref19) {
610
+ var heatmap = _ref19.heatmap,
611
+ _ref19$ssr = _ref19.ssr,
612
+ ssr = _ref19$ssr === void 0 ? UNUSED_SECTOR : _ref19$ssr,
613
+ componentsLog = _ref19.componentsLog,
614
+ viewport = _ref19.viewport;
590
615
  var lastUpdate = {};
591
616
  var totalPainted = 0;
592
617
  if (ssr !== UNUSED_SECTOR) {
@@ -655,11 +680,11 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
655
680
  });
656
681
  return VCRatio;
657
682
  }, 0);
658
- var VCEntries = entries.reduce(function (acc, _ref19, i) {
683
+ var VCEntries = entries.reduce(function (acc, _ref20, i) {
659
684
  var _acc$abs, _componentsLog$timest, _acc$rel$vc, _acc$rel;
660
- var _ref20 = (0, _slicedToArray2.default)(_ref19, 2),
661
- timestamp = _ref20[0],
662
- entryPainted = _ref20[1];
685
+ var _ref21 = (0, _slicedToArray2.default)(_ref20, 2),
686
+ timestamp = _ref21[0],
687
+ entryPainted = _ref21[1];
663
688
  var currentlyPainted = entryPainted + (((_acc$abs = acc.abs[i - 1]) === null || _acc$abs === void 0 ? void 0 : _acc$abs[1]) || 0);
664
689
  var currentlyPaintedRatio = Math.round(currentlyPainted / totalPainted * 1000) / 10;
665
690
  var logEntry = (0, _toConsumableArray2.default)(new Set((_componentsLog$timest = componentsLog[timestamp]) === null || _componentsLog$timest === void 0 ? void 0 : _componentsLog$timest.map(function (v) {
@@ -19,9 +19,10 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
19
19
  (0, _defineProperty2.default)(this, "getSizeCallbacks", new Map());
20
20
  (0, _defineProperty2.default)(this, "reactValidateCallbacks", new Map());
21
21
  (0, _defineProperty2.default)(this, "intersectionObserverCallback", function (_ref) {
22
+ var _this$intersectionObs;
22
23
  var target = _ref.target,
23
24
  boundingClientRect = _ref.boundingClientRect;
24
- _this.intersectionObserver.unobserve(target);
25
+ (_this$intersectionObs = _this.intersectionObserver) === null || _this$intersectionObs === void 0 || _this$intersectionObs.unobserve(target);
25
26
  if (!(target instanceof HTMLElement)) {
26
27
  // impossible case - keep typescript healthy
27
28
  return;
@@ -68,18 +69,21 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
68
69
  _this.reactValidateCallbacks.delete(staticKey);
69
70
  }
70
71
  });
71
- this.intersectionObserver = new IntersectionObserver(function (entries) {
72
- return entries.filter(function (entry) {
73
- return entry.intersectionRatio > 0;
74
- }).forEach(_this.intersectionObserverCallback);
75
- });
72
+ if (typeof IntersectionObserver === 'function') {
73
+ // Only instantiate the IntersectionObserver if it's supported
74
+ this.intersectionObserver = new IntersectionObserver(function (entries) {
75
+ return entries.filter(function (entry) {
76
+ return entry.intersectionRatio > 0;
77
+ }).forEach(_this.intersectionObserverCallback);
78
+ });
79
+ }
76
80
  if (window.document) {
77
81
  try {
78
82
  var existingElements = document.querySelectorAll('[data-ssr-placeholder]');
79
83
  existingElements.forEach(function (el) {
80
84
  var _el$dataset;
81
85
  if (el instanceof HTMLElement && el !== null && el !== void 0 && (_el$dataset = el.dataset) !== null && _el$dataset !== void 0 && _el$dataset.ssrPlaceholder) {
82
- var _window$__SSR_PLACEHO;
86
+ var _window$__SSR_PLACEHO, _this$intersectionObs2;
83
87
  var width = -1;
84
88
  var height = -1;
85
89
  var x = -1;
@@ -97,7 +101,7 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
97
101
  x: x,
98
102
  y: y
99
103
  });
100
- _this.intersectionObserver.observe(el);
104
+ (_this$intersectionObs2 = _this.intersectionObserver) === null || _this$intersectionObs2 === void 0 || _this$intersectionObs2.observe(el);
101
105
  }
102
106
  });
103
107
  } catch (e) {} finally {
@@ -157,8 +161,9 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
157
161
  resolve(false);
158
162
  return;
159
163
  } else {
164
+ var _this2$intersectionOb;
160
165
  _this2.callbacks.set(id, resolve);
161
- _this2.intersectionObserver.observe(el);
166
+ (_this2$intersectionOb = _this2.intersectionObserver) === null || _this2$intersectionOb === void 0 || _this2$intersectionOb.observe(el);
162
167
  }
163
168
  });
164
169
  }
@@ -167,8 +172,9 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
167
172
  value: function getSize(el) {
168
173
  var _this3 = this;
169
174
  return new Promise(function (resolve) {
175
+ var _this3$intersectionOb;
170
176
  _this3.getSizeCallbacks.set(el.dataset.ssrPlaceholder || '', resolve);
171
- _this3.intersectionObserver.observe(el);
177
+ (_this3$intersectionOb = _this3.intersectionObserver) === null || _this3$intersectionOb === void 0 || _this3$intersectionOb.observe(el);
172
178
  });
173
179
  }
174
180
  }, {
@@ -182,8 +188,9 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
182
188
  resolve(false);
183
189
  return;
184
190
  } else {
191
+ var _this4$intersectionOb;
185
192
  _this4.reactValidateCallbacks.set(id, resolve);
186
- _this4.intersectionObserver.observe(el);
193
+ (_this4$intersectionOb = _this4.intersectionObserver) === null || _this4$intersectionOb === void 0 || _this4$intersectionOb.observe(el);
187
194
  }
188
195
  });
189
196
  }
@@ -5,68 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = getElementName;
7
7
  var nameCache = new WeakMap();
8
- function getAttributeSelector(element, attributeName) {
9
- var attrValue = element.getAttribute(attributeName);
10
- if (!attrValue) {
11
- return '';
12
- }
13
- return "[".concat(attributeName, "=\"").concat(attrValue, "\"]");
14
- }
15
- function isValidSelector(selector) {
16
- try {
17
- document.querySelector(selector);
18
- return true;
19
- } catch (err) {
20
- return false;
21
- }
22
- }
23
- function isSelectorUnique(selector) {
24
- return document.querySelectorAll(selector).length === 1;
25
- }
26
- function getUniqueSelector(selectorConfig, element) {
27
- var currentElement = element;
28
- var parts = [];
29
- var MAX_DEPTH = 3;
30
- var currentDepth = 0;
31
- while (currentElement && currentElement.localName !== 'body' && currentDepth <= MAX_DEPTH) {
32
- var tagName = currentElement.localName;
33
- var selectorPart = tagName;
34
- if (selectorConfig.id && currentElement.id && isValidSelector("#".concat(currentElement.id))) {
35
- selectorPart += "#".concat(currentElement.id);
36
- } else if (selectorConfig.dataVC) {
37
- selectorPart += getAttributeSelector(currentElement, 'data-vc');
38
- } else if (selectorConfig.testId) {
39
- selectorPart += getAttributeSelector(currentElement, 'data-testid') || getAttributeSelector(currentElement, 'data-test-id');
40
- } else if (selectorConfig.role) {
41
- selectorPart += getAttributeSelector(currentElement, 'role');
42
- } else if (selectorConfig.className && currentElement.className) {
43
- var classNames = Array.from(currentElement.classList).join('.');
44
- if (classNames) {
45
- if (isValidSelector(".".concat(classNames))) {
46
- selectorPart += ".".concat(classNames);
47
- }
48
- }
49
- }
50
- parts.unshift(selectorPart);
51
- var _potentialSelector = parts.join(' > ').trim();
52
- if (_potentialSelector && isSelectorUnique(_potentialSelector)) {
53
- return _potentialSelector;
54
- }
55
- currentElement = currentElement.parentElement;
56
- currentDepth++;
57
- }
58
- var potentialSelector = parts.join(' > ').trim();
59
- if (!potentialSelector) {
60
- return 'unknown';
61
- } else if (!isSelectorUnique(potentialSelector)) {
62
- var parentElement = element.parentElement;
63
- if (parentElement) {
64
- var siblingIndex = Array.from(parentElement.children).indexOf(element) + 1;
65
- return "".concat(potentialSelector, ":nth-child(").concat(siblingIndex, ")");
66
- }
67
- }
68
- return potentialSelector;
69
- }
70
8
  function getElementName(selectorConfig, element) {
71
9
  if (!(element instanceof HTMLElement)) {
72
10
  return 'error';
@@ -75,7 +13,56 @@ function getElementName(selectorConfig, element) {
75
13
  if (cachedName) {
76
14
  return cachedName;
77
15
  }
78
- var uniqueSelector = getUniqueSelector(selectorConfig, element);
79
- nameCache.set(element, uniqueSelector);
80
- return uniqueSelector;
16
+ // Get the tag name of the element.
17
+ var tagName = element.localName;
18
+ var encodeValue = function encodeValue(s) {
19
+ try {
20
+ return encodeURIComponent(s);
21
+ } catch (e) {
22
+ return 'malformed_value';
23
+ }
24
+ };
25
+
26
+ // Helper function to construct attribute selectors.
27
+ var getAttributeSelector = function getAttributeSelector(attributeName) {
28
+ var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
29
+ var attrValue = element.getAttribute(attributeName);
30
+ if (!attrValue) {
31
+ return '';
32
+ }
33
+ var encondedAttrValue = encodeValue(attrValue);
34
+ return "".concat(prefix, "[").concat(attributeName, "=\"").concat(encondedAttrValue, "\"]");
35
+ };
36
+
37
+ // Construct the data-vc attribute selector if specified in the config.
38
+ var dataVC = selectorConfig.dataVC ? getAttributeSelector('data-vc') : '';
39
+
40
+ // Construct the ID selector if specified in the config and the element has an ID.
41
+ var id = selectorConfig.id && element.id ? "#".concat(encodeValue(element.id)) : '';
42
+
43
+ // Construct the test ID selector if specified in the config.
44
+ var testId = selectorConfig.testId ? getAttributeSelector('data-testid') || getAttributeSelector('data-test-id') : '';
45
+
46
+ // Construct the role selector if specified in the config.
47
+ var role = selectorConfig.role ? getAttributeSelector('role') : '';
48
+ var classNames = Array.from(element.classList).map(encodeValue).join('.');
49
+ // Construct the class list selector if specified in the config.
50
+ var classList = selectorConfig.className && classNames ? ".".concat(classNames) : '';
51
+
52
+ // Combine primary attribute selectors (id, testId, role) into a single string.
53
+ var primaryAttributes = [id, testId, role].filter(Boolean).join('');
54
+
55
+ // Use dataVC if available, otherwise use the primary attributes.
56
+ var attributes = dataVC || primaryAttributes;
57
+
58
+ // If no attributes or class list, recursively get the parent's name.
59
+ if (!attributes && !classList) {
60
+ var parentName = element.parentElement ? getElementName(selectorConfig, element.parentElement) : 'unknown';
61
+ return "".concat(parentName, " > ").concat(tagName);
62
+ }
63
+
64
+ // Return the final constructed name: tagName + attributes or classList.
65
+ var name = "".concat(tagName).concat(attributes || classList);
66
+ nameCache.set(element, name);
67
+ return name;
81
68
  }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = getElementName;
7
+ var nameCache = new WeakMap();
8
+ function getAttributeSelector(element, attributeName) {
9
+ var attrValue = element.getAttribute(attributeName);
10
+ if (!attrValue) {
11
+ return '';
12
+ }
13
+ return "[".concat(attributeName, "=\"").concat(attrValue, "\"]");
14
+ }
15
+ function isValidSelector(selector) {
16
+ try {
17
+ document.querySelector(selector);
18
+ return true;
19
+ } catch (err) {
20
+ return false;
21
+ }
22
+ }
23
+ function isSelectorUnique(selector) {
24
+ return document.querySelectorAll(selector).length === 1;
25
+ }
26
+ function getUniqueSelector(selectorConfig, element) {
27
+ var currentElement = element;
28
+ var parts = [];
29
+ var MAX_DEPTH = 3;
30
+ var currentDepth = 0;
31
+ while (currentElement && currentElement.localName !== 'body' && currentDepth <= MAX_DEPTH) {
32
+ var tagName = currentElement.localName;
33
+ var selectorPart = tagName;
34
+ if (selectorConfig.id && currentElement.id && isValidSelector("#".concat(currentElement.id))) {
35
+ selectorPart += "#".concat(currentElement.id);
36
+ } else if (selectorConfig.dataVC) {
37
+ selectorPart += getAttributeSelector(currentElement, 'data-vc');
38
+ } else if (selectorConfig.testId) {
39
+ selectorPart += getAttributeSelector(currentElement, 'data-testid') || getAttributeSelector(currentElement, 'data-test-id');
40
+ } else if (selectorConfig.role) {
41
+ selectorPart += getAttributeSelector(currentElement, 'role');
42
+ } else if (selectorConfig.className && currentElement.className) {
43
+ var classNames = Array.from(currentElement.classList).join('.');
44
+ if (classNames) {
45
+ if (isValidSelector(".".concat(classNames))) {
46
+ selectorPart += ".".concat(classNames);
47
+ }
48
+ }
49
+ }
50
+ parts.unshift(selectorPart);
51
+ var _potentialSelector = parts.join(' > ').trim();
52
+ if (_potentialSelector && isSelectorUnique(_potentialSelector)) {
53
+ return _potentialSelector;
54
+ }
55
+ currentElement = currentElement.parentElement;
56
+ currentDepth++;
57
+ }
58
+ var potentialSelector = parts.join(' > ').trim();
59
+ if (!potentialSelector) {
60
+ return 'unknown';
61
+ } else if (!isSelectorUnique(potentialSelector)) {
62
+ var parentElement = element.parentElement;
63
+ if (parentElement) {
64
+ return "".concat(potentialSelector, ":nth-child"); // NOTE: invalid DOM selector, but enough information for VC
65
+ }
66
+ }
67
+ return potentialSelector;
68
+ }
69
+ function getElementName(selectorConfig, element) {
70
+ if (!(element instanceof HTMLElement)) {
71
+ return 'error';
72
+ }
73
+ var cachedName = nameCache.get(element);
74
+ if (cachedName) {
75
+ return cachedName;
76
+ }
77
+ var uniqueSelector = getUniqueSelector(selectorConfig, element);
78
+ nameCache.set(element, uniqueSelector);
79
+ return uniqueSelector;
80
+ }
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.default = void 0;
7
+ exports.default = exports.KNOWN_ATTRIBUTES_THAT_DOES_NOT_CAUSE_LAYOUT_SHIFTS = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
@@ -17,6 +17,11 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
17
17
  var ABORTING_WINDOW_EVENT = ['wheel', 'scroll', 'keydown', 'resize'];
18
18
  var REVISION_NO = 'fy25.03';
19
19
  var CONSIDERED_ENTRY_TYPE = ['mutation:child-element', 'mutation:element', 'mutation:attribute', 'layout-shift', 'window:event'];
20
+
21
+ // TODO: AFO-3523
22
+ // Those are the attributes we have found when testing the 'fy25.03' manually.
23
+ // We still need to replace this hardcoded list with a proper automation
24
+ var KNOWN_ATTRIBUTES_THAT_DOES_NOT_CAUSE_LAYOUT_SHIFTS = exports.KNOWN_ATTRIBUTES_THAT_DOES_NOT_CAUSE_LAYOUT_SHIFTS = ['data-drop-target-for-element', 'draggable'];
20
25
  var VCCalculator_FY25_03 = exports.default = /*#__PURE__*/function (_AbstractVCCalculator) {
21
26
  function VCCalculator_FY25_03() {
22
27
  (0, _classCallCheck2.default)(this, VCCalculator_FY25_03);
@@ -32,7 +37,7 @@ var VCCalculator_FY25_03 = exports.default = /*#__PURE__*/function (_AbstractVCC
32
37
  if (entry.type === 'mutation:attribute') {
33
38
  var entryData = entry.data;
34
39
  var attributeName = entryData.attributeName;
35
- if (!attributeName) {
40
+ if (!attributeName || KNOWN_ATTRIBUTES_THAT_DOES_NOT_CAUSE_LAYOUT_SHIFTS.includes(attributeName)) {
36
41
  return false;
37
42
  }
38
43
  return true;
@@ -41,12 +41,14 @@ var ViewportCanvas = exports.ViewportCanvas = /*#__PURE__*/function () {
41
41
  this.scaleFactor = scaleFactor;
42
42
  this.colorCounter = 1;
43
43
  this.colorTimeMap = new Map();
44
+ var safeViewportWidth = Math.max(viewport.width, 1);
45
+ var safeViewportHeight = Math.max(viewport.height, 1);
44
46
 
45
47
  // Calculate scaled dimensions
46
- this.scaledWidth = Math.ceil(viewport.width * scaleFactor);
47
- this.scaledHeight = Math.ceil(viewport.height * scaleFactor);
48
- this.scaleX = this.scaledWidth / viewport.width;
49
- this.scaleY = this.scaledHeight / viewport.height;
48
+ this.scaledWidth = Math.max(Math.ceil(safeViewportWidth * scaleFactor), 1);
49
+ this.scaledHeight = Math.max(Math.ceil(safeViewportHeight * scaleFactor), 1);
50
+ this.scaleX = this.scaledWidth / safeViewportWidth;
51
+ this.scaleY = this.scaledHeight / safeViewportHeight;
50
52
 
51
53
  // Initialize OffscreenCanvas with scaled dimensions
52
54
  this.canvas = document.createElement('canvas');
@@ -21,7 +21,9 @@ function isElementVisible(element) {
21
21
  try {
22
22
  var visible = element.checkVisibility({
23
23
  // @ts-expect-error
24
- visibilityProperty: true
24
+ visibilityProperty: true,
25
+ contentVisibilityAuto: true,
26
+ opacityProperty: true
25
27
  });
26
28
  return visible;
27
29
  } catch (e) {
@@ -54,6 +56,9 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
54
56
  time = _ref2.time,
55
57
  type = _ref2.type,
56
58
  mutationData = _ref2.mutationData;
59
+ if (!target) {
60
+ return;
61
+ }
57
62
  var visible = isElementVisible(target);
58
63
  var lastElementRect = _this.mapVisibleNodeRects.get(target);
59
64
  _this.mapVisibleNodeRects.set(target, rect);
@@ -149,14 +154,17 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
149
154
  try {
150
155
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
151
156
  var changedRect = _step.value;
152
- onChange({
153
- time: time,
154
- elementRef: new WeakRef(changedRect.node),
155
- visible: true,
156
- rect: changedRect.rect,
157
- previousRect: changedRect.previousRect,
158
- type: 'layout-shift'
159
- });
157
+ var target = changedRect.node;
158
+ if (target) {
159
+ onChange({
160
+ time: time,
161
+ elementRef: new WeakRef(target),
162
+ visible: true,
163
+ rect: changedRect.rect,
164
+ previousRect: changedRect.previousRect,
165
+ type: 'layout-shift'
166
+ });
167
+ }
160
168
  }
161
169
  } catch (err) {
162
170
  _iterator.e(err);
@@ -2,6 +2,10 @@ import { PerformanceObserverEntryTypes } from '../../const';
2
2
  import { EntriesBuffer } from '../buffer';
3
3
  let pe = null;
4
4
  const getObserver = () => {
5
+ if (typeof PerformanceObserver !== 'function') {
6
+ // Only instantiate the IntersectionObserver if it's supported
7
+ return null;
8
+ }
5
9
  if (pe !== null) {
6
10
  return pe;
7
11
  }
@@ -18,13 +22,15 @@ const getObserver = () => {
18
22
  return pe;
19
23
  };
20
24
  export const startLSObserver = () => {
21
- getObserver().observe({
25
+ var _getObserver;
26
+ (_getObserver = getObserver()) === null || _getObserver === void 0 ? void 0 : _getObserver.observe({
22
27
  type: PerformanceObserverEntryTypes.LayoutShift,
23
28
  buffered: true
24
29
  });
25
30
  };
26
31
  export const startLTObserver = () => {
27
- getObserver().observe({
32
+ var _getObserver2;
33
+ (_getObserver2 = getObserver()) === null || _getObserver2 === void 0 ? void 0 : _getObserver2.observe({
28
34
  type: PerformanceObserverEntryTypes.LongTask,
29
35
  buffered: true
30
36
  });