@atlaskit/react-ufo 3.4.1 → 3.4.3

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 (48) 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/index.js +22 -2
  6. package/dist/cjs/vc/no-op-vc-observer.js +44 -0
  7. package/dist/cjs/vc/vc-observer/index.js +74 -46
  8. package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/index.js +18 -11
  9. package/dist/cjs/vc/vc-observer-new/get-element-name.js +52 -64
  10. package/dist/cjs/vc/vc-observer-new/get-unique-element-name.js +80 -0
  11. package/dist/cjs/vc/vc-observer-new/metric-calculator/fy25_03/index.js +7 -2
  12. package/dist/cjs/vc/vc-observer-new/metric-calculator/percentile-calc/canvas-heatmap/canvas-pixel.js +6 -4
  13. package/dist/cjs/vc/vc-observer-new/viewport-observer/index.js +17 -9
  14. package/dist/es2019/additional-payload/utils/lighthouse-metrics/utils/observer/index.js +8 -2
  15. package/dist/es2019/create-payload/index.js +39 -3
  16. package/dist/es2019/segment/segment.js +29 -3
  17. package/dist/es2019/vc/index.js +22 -2
  18. package/dist/es2019/vc/no-op-vc-observer.js +17 -0
  19. package/dist/es2019/vc/vc-observer/index.js +42 -12
  20. package/dist/es2019/vc/vc-observer/observers/ssr-placeholders/index.js +14 -7
  21. package/dist/es2019/vc/vc-observer-new/get-element-name.js +51 -64
  22. package/dist/es2019/vc/vc-observer-new/get-unique-element-name.js +74 -0
  23. package/dist/es2019/vc/vc-observer-new/metric-calculator/fy25_03/index.js +6 -1
  24. package/dist/es2019/vc/vc-observer-new/metric-calculator/percentile-calc/canvas-heatmap/canvas-pixel.js +6 -4
  25. package/dist/es2019/vc/vc-observer-new/viewport-observer/index.js +17 -9
  26. package/dist/esm/additional-payload/utils/lighthouse-metrics/utils/observer/index.js +8 -2
  27. package/dist/esm/create-payload/index.js +136 -76
  28. package/dist/esm/segment/segment.js +29 -4
  29. package/dist/esm/vc/index.js +22 -2
  30. package/dist/esm/vc/no-op-vc-observer.js +37 -0
  31. package/dist/esm/vc/vc-observer/index.js +74 -46
  32. package/dist/esm/vc/vc-observer/observers/ssr-placeholders/index.js +18 -11
  33. package/dist/esm/vc/vc-observer-new/get-element-name.js +52 -64
  34. package/dist/esm/vc/vc-observer-new/get-unique-element-name.js +74 -0
  35. package/dist/esm/vc/vc-observer-new/metric-calculator/fy25_03/index.js +6 -1
  36. package/dist/esm/vc/vc-observer-new/metric-calculator/percentile-calc/canvas-heatmap/canvas-pixel.js +6 -4
  37. package/dist/esm/vc/vc-observer-new/viewport-observer/index.js +17 -9
  38. package/dist/types/interaction-context/index.d.ts +2 -0
  39. package/dist/types/segment/segment.d.ts +2 -1
  40. package/dist/types/vc/no-op-vc-observer.d.ts +13 -0
  41. package/dist/types/vc/vc-observer-new/get-unique-element-name.d.ts +8 -0
  42. package/dist/types/vc/vc-observer-new/metric-calculator/fy25_03/index.d.ts +1 -0
  43. package/dist/types-ts4.5/interaction-context/index.d.ts +2 -0
  44. package/dist/types-ts4.5/segment/segment.d.ts +2 -1
  45. package/dist/types-ts4.5/vc/no-op-vc-observer.d.ts +13 -0
  46. package/dist/types-ts4.5/vc/vc-observer-new/get-unique-element-name.d.ts +8 -0
  47. package/dist/types-ts4.5/vc/vc-observer-new/metric-calculator/fy25_03/index.d.ts +1 -0
  48. package/package.json +7 -1
@@ -14,6 +14,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
14
14
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
15
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
16
16
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
+ var _hiddenTiming = require("../../hidden-timing");
17
18
  var _attachAbortListeners = require("./attachAbortListeners");
18
19
  var _getViewport = require("./getViewport");
19
20
  var _heatmap = require("./heatmap/heatmap");
@@ -103,7 +104,7 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
103
104
  });
104
105
  (0, _defineProperty2.default)(this, "getVCResult", /*#__PURE__*/function () {
105
106
  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;
107
+ 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, pageVisibilityUpToTTAI, shouldHaveVCmetric, revisionsData, isCalcSpeedIndexEnabled, speedIndex;
107
108
  return _regenerator.default.wrap(function _callee$(_context) {
108
109
  while (1) switch (_context.prev = _context.next) {
109
110
  case 0:
@@ -240,31 +241,56 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
240
241
  } catch (e) {
241
242
  /* do nothing */
242
243
  }
244
+ isVCClean = !abortReasonInfo;
243
245
  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({
246
+ pageVisibilityUpToTTAI = (0, _hiddenTiming.getPageVisibilityState)(start, stop);
247
+ shouldHaveVCmetric = isVCClean && !isEventAborted && pageVisibilityUpToTTAI;
248
+ revisionsData = isMultiHeatmapEnabled ? (0, _platformFeatureFlags.fg)('platform_ufo_vc_observer_new') ? (0, _defineProperty2.default)({}, "".concat(fullPrefix, "vc:rev"), [{
249
+ revision: 'fy25.01',
250
+ clean: isVCClean,
251
+ 'metric:vc90': shouldHaveVCmetric ? VC['90'] : null,
252
+ vcDetails: shouldHaveVCmetric ? Object.fromEntries(VCObserver.VCParts.map(function (key) {
253
+ var _VCBox$key;
254
+ return [key, {
255
+ t: VC[key],
256
+ e: (_VCBox$key = VCBox[key]) !== null && _VCBox$key !== void 0 ? _VCBox$key : []
257
+ }];
258
+ })) : []
259
+ }, {
260
+ revision: 'fy25.02',
261
+ clean: isVCClean,
262
+ 'metric:vc90': shouldHaveVCmetric ? VC['90'] : null,
263
+ vcDetails: shouldHaveVCmetric ? Object.fromEntries(VCObserver.VCParts.map(function (key) {
264
+ var _vcNext$VCBox$key;
265
+ return [key, {
266
+ t: vcNext.VC[key],
267
+ e: (_vcNext$VCBox$key = vcNext.VCBox[key]) !== null && _vcNext$VCBox$key !== void 0 ? _vcNext$VCBox$key : []
268
+ }];
269
+ })) : []
270
+ }]) : multiHeatmap !== null ? (0, _defineProperty2.default)({}, "".concat(fullPrefix, "vc:rev"), multiHeatmap === null || multiHeatmap === void 0 ? void 0 : multiHeatmap.getPayloadShapedData({
245
271
  VCParts: VCObserver.VCParts.map(function (v) {
246
272
  return parseInt(v);
247
273
  }),
248
- VCCalculationMethods: (0, _revisions.getRevisions)().map(function (_ref9) {
249
- var classifier = _ref9.classifier;
274
+ VCCalculationMethods: (0, _revisions.getRevisions)().map(function (_ref10) {
275
+ var classifier = _ref10.classifier;
250
276
  return classifier.VCCalculationMethod;
251
277
  }),
252
- filterComponentsLog: (0, _revisions.getRevisions)().map(function (_ref10) {
253
- var classifier = _ref10.classifier;
278
+ filterComponentsLog: (0, _revisions.getRevisions)().map(function (_ref11) {
279
+ var classifier = _ref11.classifier;
254
280
  return classifier.filterComponentsLog;
255
281
  }),
256
282
  isEventAborted: isEventAborted,
257
283
  interactionStart: start,
258
284
  ttai: stop,
259
285
  ssr: ssr,
260
- clean: !abortReasonInfo
261
- })) : null; // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
286
+ clean: isVCClean
287
+ })) : null : null; // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
262
288
  isCalcSpeedIndexEnabled = (0, _platformFeatureFlags.fg)('ufo-calc-speed-index');
263
289
  speedIndex = (0, _defineProperty2.default)((0, _defineProperty2.default)({}, "ufo:speedIndex", VCEntries.speedIndex), "ufo:next:speedIndex", vcNext.VCEntries.speedIndex);
264
290
  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
291
  '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:
292
+ }, "".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 : {}));
293
+ case 27:
268
294
  case "end":
269
295
  return _context.stop();
270
296
  }
@@ -277,14 +303,16 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
277
303
  (0, _defineProperty2.default)(this, "handleUpdate", function (rawTime, intersectionRect, targetName, element, type, ignoreReason) {
278
304
  _this.measureStart();
279
305
  _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
- });
306
+ if (!(0, _platformFeatureFlags.fg)('platform_ufo_vc_observer_new')) {
307
+ _this.onViewportChangeDetected({
308
+ timestamp: rawTime,
309
+ intersectionRect: intersectionRect,
310
+ targetName: targetName,
311
+ element: element,
312
+ type: type,
313
+ ignoreReason: ignoreReason
314
+ });
315
+ }
288
316
  _this.measureStop();
289
317
  });
290
318
  (0, _defineProperty2.default)(this, "legacyHandleUpdate", function (rawTime, intersectionRect, targetName, element, type, ignoreReason) {
@@ -309,13 +337,13 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
309
337
  });
310
338
  }
311
339
  });
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;
340
+ (0, _defineProperty2.default)(this, "onViewportChangeDetected", function (_ref13) {
341
+ var element = _ref13.element,
342
+ type = _ref13.type,
343
+ ignoreReason = _ref13.ignoreReason,
344
+ timestamp = _ref13.timestamp,
345
+ targetName = _ref13.targetName,
346
+ intersectionRect = _ref13.intersectionRect;
319
347
  if (_this.multiHeatmap === null) {
320
348
  return;
321
349
  }
@@ -397,10 +425,10 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
397
425
  var unbinds = (0, _attachAbortListeners.attachAbortListeners)(window, _this.viewport, _this.abortReasonCallback);
398
426
  if ((_window = window) !== null && _window !== void 0 && _window.__SSR_ABORT_LISTENERS__) {
399
427
  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];
428
+ Object.entries(window.__SSR_ABORT_LISTENERS__.aborts).forEach(function (_ref14) {
429
+ var _ref15 = (0, _slicedToArray2.default)(_ref14, 2),
430
+ key = _ref15[0],
431
+ time = _ref15[1];
404
432
  if (time) {
405
433
  _this.abortReasonCallback(key, time);
406
434
  }
@@ -433,8 +461,8 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
433
461
  }
434
462
  return (0, _createClass2.default)(VCObserver, [{
435
463
  key: "start",
436
- value: function start(_ref15) {
437
- var startTime = _ref15.startTime;
464
+ value: function start(_ref16) {
465
+ var startTime = _ref16.startTime;
438
466
  this.active = true;
439
467
  if (this.observers.isBrowserSupported()) {
440
468
  this.setViewportSize();
@@ -456,12 +484,12 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
456
484
  }, {
457
485
  key: "getIgnoredElements",
458
486
  value: function getIgnoredElements(componentsLog) {
459
- return Object.values(componentsLog).flat().filter(function (_ref16) {
460
- var ignoreReason = _ref16.ignoreReason;
487
+ return Object.values(componentsLog).flat().filter(function (_ref17) {
488
+ var ignoreReason = _ref17.ignoreReason;
461
489
  return Boolean(ignoreReason);
462
- }).map(function (_ref17) {
463
- var targetName = _ref17.targetName,
464
- ignoreReason = _ref17.ignoreReason;
490
+ }).map(function (_ref18) {
491
+ var targetName = _ref18.targetName,
492
+ ignoreReason = _ref18.ignoreReason;
465
493
  return {
466
494
  targetName: targetName,
467
495
  ignoreReason: ignoreReason
@@ -581,12 +609,12 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
581
609
  }
582
610
  }], [{
583
611
  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;
612
+ value: function calculateVC(_ref19) {
613
+ var heatmap = _ref19.heatmap,
614
+ _ref19$ssr = _ref19.ssr,
615
+ ssr = _ref19$ssr === void 0 ? UNUSED_SECTOR : _ref19$ssr,
616
+ componentsLog = _ref19.componentsLog,
617
+ viewport = _ref19.viewport;
590
618
  var lastUpdate = {};
591
619
  var totalPainted = 0;
592
620
  if (ssr !== UNUSED_SECTOR) {
@@ -655,11 +683,11 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
655
683
  });
656
684
  return VCRatio;
657
685
  }, 0);
658
- var VCEntries = entries.reduce(function (acc, _ref19, i) {
686
+ var VCEntries = entries.reduce(function (acc, _ref20, i) {
659
687
  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];
688
+ var _ref21 = (0, _slicedToArray2.default)(_ref20, 2),
689
+ timestamp = _ref21[0],
690
+ entryPainted = _ref21[1];
663
691
  var currentlyPainted = entryPainted + (((_acc$abs = acc.abs[i - 1]) === null || _acc$abs === void 0 ? void 0 : _acc$abs[1]) || 0);
664
692
  var currentlyPaintedRatio = Math.round(currentlyPainted / totalPainted * 1000) / 10;
665
693
  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,67 +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
- return "".concat(potentialSelector, ":nth-child"); // NOTE: invalid DOM selector, but enough information for VC
65
- }
66
- }
67
- return potentialSelector;
68
- }
69
8
  function getElementName(selectorConfig, element) {
70
9
  if (!(element instanceof HTMLElement)) {
71
10
  return 'error';
@@ -74,7 +13,56 @@ function getElementName(selectorConfig, element) {
74
13
  if (cachedName) {
75
14
  return cachedName;
76
15
  }
77
- var uniqueSelector = getUniqueSelector(selectorConfig, element);
78
- nameCache.set(element, uniqueSelector);
79
- 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;
80
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
  });