@atlaskit/react-ufo 4.3.1 → 4.3.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.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.js +5 -1
- package/dist/cjs/vc/vc-observer-new/viewport-observer/index.js +29 -13
- package/dist/cjs/vc/vc-observer-new/viewport-observer/intersection-observer/index.js +9 -0
- package/dist/cjs/vc/vc-observer-new/viewport-observer/utils/check-display-content.js +48 -0
- package/dist/es2019/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.js +4 -0
- package/dist/es2019/vc/vc-observer-new/viewport-observer/index.js +16 -6
- package/dist/es2019/vc/vc-observer-new/viewport-observer/intersection-observer/index.js +9 -0
- package/dist/es2019/vc/vc-observer-new/viewport-observer/utils/check-display-content.js +27 -0
- package/dist/esm/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.js +5 -1
- package/dist/esm/vc/vc-observer-new/viewport-observer/index.js +29 -13
- package/dist/esm/vc/vc-observer-new/viewport-observer/intersection-observer/index.js +9 -0
- package/dist/esm/vc/vc-observer-new/viewport-observer/utils/check-display-content.js +39 -0
- package/dist/types/common/vc/types.d.ts +1 -0
- package/dist/types/vc/vc-observer-new/viewport-observer/utils/check-display-content.d.ts +4 -0
- package/dist/types-ts4.5/common/vc/types.d.ts +1 -0
- package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/utils/check-display-content.d.ts +4 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/ufo-interaction-ignore
|
|
2
2
|
|
|
3
|
+
## 4.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`7cf45d7a0ce8d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7cf45d7a0ce8d) -
|
|
8
|
+
Include elements with display:contents css property in TTVC
|
|
9
|
+
|
|
3
10
|
## 4.3.1
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -13,6 +13,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
13
13
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
14
14
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
15
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
16
|
+
var _checkDisplayContent = require("../viewport-observer/utils/check-display-content");
|
|
16
17
|
var _percentileCalc = require("./percentile-calc");
|
|
17
18
|
var _getViewportHeight = _interopRequireDefault(require("./utils/get-viewport-height"));
|
|
18
19
|
var _getViewportWidth = _interopRequireDefault(require("./utils/get-viewport-width"));
|
|
@@ -355,8 +356,11 @@ var AbstractVCCalculatorBase = exports.default = /*#__PURE__*/function () {
|
|
|
355
356
|
vcDetails: vcDetails !== null && vcDetails !== void 0 ? vcDetails : undefined
|
|
356
357
|
};
|
|
357
358
|
result.ratios = this.calculateRatios(filteredEntries);
|
|
359
|
+
if ((0, _platformFeatureFlags.fg)('platform_ufo_display_content_resolution_ttvc_v3')) {
|
|
360
|
+
result.childrenIgnoredCount = (0, _checkDisplayContent.getInvalidChildrenCount)();
|
|
361
|
+
}
|
|
358
362
|
return _context2.abrupt("return", result);
|
|
359
|
-
case
|
|
363
|
+
case 14:
|
|
360
364
|
case "end":
|
|
361
365
|
return _context2.stop();
|
|
362
366
|
}
|
|
@@ -18,6 +18,7 @@ var _rllPlaceholders = require("../../vc-observer/observers/rll-placeholders");
|
|
|
18
18
|
var _intersectionObserver = require("./intersection-observer");
|
|
19
19
|
var _mutationObserver = _interopRequireDefault(require("./mutation-observer"));
|
|
20
20
|
var _performanceObserver = _interopRequireDefault(require("./performance-observer"));
|
|
21
|
+
var _checkDisplayContent = _interopRequireDefault(require("./utils/check-display-content"));
|
|
21
22
|
var _checkWithinComponent2 = _interopRequireWildcard(require("./utils/check-within-component"));
|
|
22
23
|
var _isInVcIgnoreIfNoLayoutShiftMarker = _interopRequireDefault(require("./utils/is-in-vc-ignore-if-no-layout-shift-marker"));
|
|
23
24
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
@@ -123,8 +124,7 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
|
|
|
123
124
|
_iterator = _createForOfIteratorHelper(addedNodes);
|
|
124
125
|
_context2.prev = 4;
|
|
125
126
|
_loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
|
|
126
|
-
var _this$intersectionObs9;
|
|
127
|
-
var addedNodeRef, addedNode, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, _this$intersectionObs3, result, _this$intersectionObs4, _result, _this$intersectionObs5, sameDeletedNode, isInIgnoreLsMarker, _this$intersectionObs6, _this$intersectionObs7, _checkWithinComponent, isWithinThirdPartySegment, _this$intersectionObs8;
|
|
127
|
+
var addedNodeRef, addedNode, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, _this$intersectionObs3, result, _this$intersectionObs4, _result, _this$intersectionObs5, sameDeletedNode, isInIgnoreLsMarker, _this$intersectionObs6, _this$intersectionObs7, _checkWithinComponent, isWithinThirdPartySegment, _this$intersectionObs8, validTargets, _iterator2, _step2, _this$intersectionObs9, validTarget, _this$intersectionObs0;
|
|
128
128
|
return _regenerator.default.wrap(function _loop$(_context) {
|
|
129
129
|
while (1) switch (_context.prev = _context.next) {
|
|
130
130
|
case 0:
|
|
@@ -254,7 +254,23 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
|
|
|
254
254
|
(_this$intersectionObs8 = _this.intersectionObserver) === null || _this$intersectionObs8 === void 0 || _this$intersectionObs8.watchAndTag(addedNode, 'mutation:third-party-element');
|
|
255
255
|
return _context.abrupt("return", 0);
|
|
256
256
|
case 54:
|
|
257
|
-
(
|
|
257
|
+
if ((0, _platformFeatureFlags.fg)('platform_ufo_display_content_resolution_ttvc_v3')) {
|
|
258
|
+
// Check if the target has display:content css property, return array of valid targets
|
|
259
|
+
validTargets = (0, _checkDisplayContent.default)(addedNode);
|
|
260
|
+
_iterator2 = _createForOfIteratorHelper(validTargets);
|
|
261
|
+
try {
|
|
262
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
263
|
+
validTarget = _step2.value;
|
|
264
|
+
(_this$intersectionObs9 = _this.intersectionObserver) === null || _this$intersectionObs9 === void 0 || _this$intersectionObs9.watchAndTag(validTarget, createElementMutationsWatcher(removedNodeRects));
|
|
265
|
+
}
|
|
266
|
+
} catch (err) {
|
|
267
|
+
_iterator2.e(err);
|
|
268
|
+
} finally {
|
|
269
|
+
_iterator2.f();
|
|
270
|
+
}
|
|
271
|
+
} else {
|
|
272
|
+
(_this$intersectionObs0 = _this.intersectionObserver) === null || _this$intersectionObs0 === void 0 || _this$intersectionObs0.watchAndTag(addedNode, createElementMutationsWatcher(removedNodeRects));
|
|
273
|
+
}
|
|
258
274
|
case 55:
|
|
259
275
|
case "end":
|
|
260
276
|
return _context.stop();
|
|
@@ -300,12 +316,12 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
|
|
|
300
316
|
};
|
|
301
317
|
}());
|
|
302
318
|
(0, _defineProperty2.default)(this, "handleAttributeMutation", function (_ref6) {
|
|
303
|
-
var _this$
|
|
319
|
+
var _this$intersectionObs1;
|
|
304
320
|
var target = _ref6.target,
|
|
305
321
|
attributeName = _ref6.attributeName,
|
|
306
322
|
oldValue = _ref6.oldValue,
|
|
307
323
|
newValue = _ref6.newValue;
|
|
308
|
-
(_this$
|
|
324
|
+
(_this$intersectionObs1 = _this.intersectionObserver) === null || _this$intersectionObs1 === void 0 || _this$intersectionObs1.watchAndTag(target, function (_ref7) {
|
|
309
325
|
var target = _ref7.target,
|
|
310
326
|
rect = _ref7.rect;
|
|
311
327
|
if ((0, _vcUtils.isContainedWithinMediaWrapper)(target)) {
|
|
@@ -368,11 +384,11 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
|
|
|
368
384
|
(0, _defineProperty2.default)(this, "handleLayoutShift", function (_ref8) {
|
|
369
385
|
var time = _ref8.time,
|
|
370
386
|
changedRects = _ref8.changedRects;
|
|
371
|
-
var
|
|
372
|
-
|
|
387
|
+
var _iterator3 = _createForOfIteratorHelper(changedRects),
|
|
388
|
+
_step3;
|
|
373
389
|
try {
|
|
374
|
-
for (
|
|
375
|
-
var changedRect =
|
|
390
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
391
|
+
var changedRect = _step3.value;
|
|
376
392
|
var target = changedRect.node;
|
|
377
393
|
if (target) {
|
|
378
394
|
_this.onChange({
|
|
@@ -386,9 +402,9 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
|
|
|
386
402
|
}
|
|
387
403
|
}
|
|
388
404
|
} catch (err) {
|
|
389
|
-
|
|
405
|
+
_iterator3.e(err);
|
|
390
406
|
} finally {
|
|
391
|
-
|
|
407
|
+
_iterator3.f();
|
|
392
408
|
}
|
|
393
409
|
});
|
|
394
410
|
this.mapVisibleNodeRects = new WeakMap();
|
|
@@ -445,12 +461,12 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
|
|
|
445
461
|
}, {
|
|
446
462
|
key: "stop",
|
|
447
463
|
value: function stop() {
|
|
448
|
-
var _this$mutationObserve2, _this$
|
|
464
|
+
var _this$mutationObserve2, _this$intersectionObs10, _this$performanceObse2;
|
|
449
465
|
if (!this.isStarted) {
|
|
450
466
|
return;
|
|
451
467
|
}
|
|
452
468
|
(_this$mutationObserve2 = this.mutationObserver) === null || _this$mutationObserve2 === void 0 || _this$mutationObserve2.disconnect();
|
|
453
|
-
(_this$
|
|
469
|
+
(_this$intersectionObs10 = this.intersectionObserver) === null || _this$intersectionObs10 === void 0 || _this$intersectionObs10.disconnect();
|
|
454
470
|
(_this$performanceObse2 = this.performanceObserver) === null || _this$performanceObse2 === void 0 || _this$performanceObse2.disconnect();
|
|
455
471
|
this.isStarted = false;
|
|
456
472
|
// Clean up caches when stopping
|
|
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createIntersectionObserver = createIntersectionObserver;
|
|
7
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
8
|
+
var _checkDisplayContent = require("../utils/check-display-content");
|
|
7
9
|
function isValidEntry(entry) {
|
|
8
10
|
return entry.isIntersecting && entry.intersectionRect.width > 0 && entry.intersectionRect.height > 0;
|
|
9
11
|
}
|
|
@@ -19,6 +21,13 @@ function createIntersectionObserver(_ref) {
|
|
|
19
21
|
var startTime = performance.now();
|
|
20
22
|
entries.forEach(function (entry) {
|
|
21
23
|
if (!(entry.target instanceof HTMLElement) || !isValidEntry(entry)) {
|
|
24
|
+
// TODO: Remove this logic when analysis is complete
|
|
25
|
+
if ((0, _platformFeatureFlags.fg)('platform_ufo_display_content_resolution_ttvc_v3')) {
|
|
26
|
+
if (entry.target instanceof HTMLElement && !isValidEntry(entry) && _checkDisplayContent.checkedChildrenCache.get(entry.target) === false) {
|
|
27
|
+
(0, _checkDisplayContent.incrementCheckedInvalidChildrenCount)();
|
|
28
|
+
_checkDisplayContent.checkedChildrenCache.set(entry.target, true);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
22
31
|
return;
|
|
23
32
|
}
|
|
24
33
|
var mutationTag = null;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkedChildrenCache = void 0;
|
|
7
|
+
exports.default = checkCssProperty;
|
|
8
|
+
exports.getInvalidChildrenCount = getInvalidChildrenCount;
|
|
9
|
+
exports.incrementCheckedInvalidChildrenCount = incrementCheckedInvalidChildrenCount;
|
|
10
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
11
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
12
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
13
|
+
// TODO: Remove this cache when analysis is complete - it is used to track whether direct children elements will be ignored by the observer
|
|
14
|
+
var checkedChildrenCache = exports.checkedChildrenCache = new WeakMap();
|
|
15
|
+
var checkedInvalidChildrenCount = 0;
|
|
16
|
+
function incrementCheckedInvalidChildrenCount() {
|
|
17
|
+
checkedInvalidChildrenCount++;
|
|
18
|
+
}
|
|
19
|
+
function getInvalidChildrenCount() {
|
|
20
|
+
return checkedInvalidChildrenCount;
|
|
21
|
+
}
|
|
22
|
+
function checkCssProperty(element) {
|
|
23
|
+
var computedStyle = window.getComputedStyle(element);
|
|
24
|
+
if (computedStyle.display === 'contents') {
|
|
25
|
+
// If display is 'contents', we return the direct children of the element
|
|
26
|
+
var result = [];
|
|
27
|
+
var _iterator = _createForOfIteratorHelper(element.children),
|
|
28
|
+
_step;
|
|
29
|
+
try {
|
|
30
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
31
|
+
var child = _step.value;
|
|
32
|
+
if (child instanceof HTMLElement) {
|
|
33
|
+
if (!checkedChildrenCache.has(child)) {
|
|
34
|
+
// TODO: Remove this cache when analysis is complete
|
|
35
|
+
checkedChildrenCache.set(child, false);
|
|
36
|
+
}
|
|
37
|
+
result.push(child);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} catch (err) {
|
|
41
|
+
_iterator.e(err);
|
|
42
|
+
} finally {
|
|
43
|
+
_iterator.f();
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
return [element];
|
|
48
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
import { getInvalidChildrenCount } from '../viewport-observer/utils/check-display-content';
|
|
2
3
|
import { calculateTTVCPercentilesWithDebugInfo } from './percentile-calc';
|
|
3
4
|
import getViewportHeight from './utils/get-viewport-height';
|
|
4
5
|
import getViewportWidth from './utils/get-viewport-width';
|
|
@@ -245,6 +246,9 @@ export default class AbstractVCCalculatorBase {
|
|
|
245
246
|
vcDetails: vcDetails !== null && vcDetails !== void 0 ? vcDetails : undefined
|
|
246
247
|
};
|
|
247
248
|
result.ratios = this.calculateRatios(filteredEntries);
|
|
249
|
+
if (fg('platform_ufo_display_content_resolution_ttvc_v3')) {
|
|
250
|
+
result.childrenIgnoredCount = getInvalidChildrenCount();
|
|
251
|
+
}
|
|
248
252
|
return result;
|
|
249
253
|
}
|
|
250
254
|
}
|
|
@@ -6,6 +6,7 @@ import { RLLPlaceholderHandlers } from '../../vc-observer/observers/rll-placehol
|
|
|
6
6
|
import { createIntersectionObserver } from './intersection-observer';
|
|
7
7
|
import createMutationObserver from './mutation-observer';
|
|
8
8
|
import createPerformanceObserver from './performance-observer';
|
|
9
|
+
import checkCssProperty from './utils/check-display-content';
|
|
9
10
|
import checkWithinComponent, { cleanupCaches } from './utils/check-within-component';
|
|
10
11
|
import isInVCIgnoreIfNoLayoutShiftMarker from './utils/is-in-vc-ignore-if-no-layout-shift-marker';
|
|
11
12
|
function isElementVisible(element) {
|
|
@@ -101,7 +102,6 @@ export default class ViewportObserver {
|
|
|
101
102
|
});
|
|
102
103
|
const targetNode = target.deref();
|
|
103
104
|
for (const addedNodeRef of addedNodes) {
|
|
104
|
-
var _this$intersectionObs9;
|
|
105
105
|
const addedNode = addedNodeRef.deref();
|
|
106
106
|
if (!addedNode) {
|
|
107
107
|
continue;
|
|
@@ -194,7 +194,17 @@ export default class ViewportObserver {
|
|
|
194
194
|
(_this$intersectionObs8 = this.intersectionObserver) === null || _this$intersectionObs8 === void 0 ? void 0 : _this$intersectionObs8.watchAndTag(addedNode, 'mutation:third-party-element');
|
|
195
195
|
continue;
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
if (fg('platform_ufo_display_content_resolution_ttvc_v3')) {
|
|
198
|
+
// Check if the target has display:content css property, return array of valid targets
|
|
199
|
+
const validTargets = checkCssProperty(addedNode);
|
|
200
|
+
for (const validTarget of validTargets) {
|
|
201
|
+
var _this$intersectionObs9;
|
|
202
|
+
(_this$intersectionObs9 = this.intersectionObserver) === null || _this$intersectionObs9 === void 0 ? void 0 : _this$intersectionObs9.watchAndTag(validTarget, createElementMutationsWatcher(removedNodeRects));
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
var _this$intersectionObs0;
|
|
206
|
+
(_this$intersectionObs0 = this.intersectionObserver) === null || _this$intersectionObs0 === void 0 ? void 0 : _this$intersectionObs0.watchAndTag(addedNode, createElementMutationsWatcher(removedNodeRects));
|
|
207
|
+
}
|
|
198
208
|
}
|
|
199
209
|
});
|
|
200
210
|
_defineProperty(this, "handleAttributeMutation", ({
|
|
@@ -203,8 +213,8 @@ export default class ViewportObserver {
|
|
|
203
213
|
oldValue,
|
|
204
214
|
newValue
|
|
205
215
|
}) => {
|
|
206
|
-
var _this$
|
|
207
|
-
(_this$
|
|
216
|
+
var _this$intersectionObs1;
|
|
217
|
+
(_this$intersectionObs1 = this.intersectionObserver) === null || _this$intersectionObs1 === void 0 ? void 0 : _this$intersectionObs1.watchAndTag(target, ({
|
|
208
218
|
target,
|
|
209
219
|
rect
|
|
210
220
|
}) => {
|
|
@@ -331,12 +341,12 @@ export default class ViewportObserver {
|
|
|
331
341
|
this.isStarted = true;
|
|
332
342
|
}
|
|
333
343
|
stop() {
|
|
334
|
-
var _this$mutationObserve2, _this$
|
|
344
|
+
var _this$mutationObserve2, _this$intersectionObs10, _this$performanceObse2;
|
|
335
345
|
if (!this.isStarted) {
|
|
336
346
|
return;
|
|
337
347
|
}
|
|
338
348
|
(_this$mutationObserve2 = this.mutationObserver) === null || _this$mutationObserve2 === void 0 ? void 0 : _this$mutationObserve2.disconnect();
|
|
339
|
-
(_this$
|
|
349
|
+
(_this$intersectionObs10 = this.intersectionObserver) === null || _this$intersectionObs10 === void 0 ? void 0 : _this$intersectionObs10.disconnect();
|
|
340
350
|
(_this$performanceObse2 = this.performanceObserver) === null || _this$performanceObse2 === void 0 ? void 0 : _this$performanceObse2.disconnect();
|
|
341
351
|
this.isStarted = false;
|
|
342
352
|
// Clean up caches when stopping
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
import { checkedChildrenCache, incrementCheckedInvalidChildrenCount } from '../utils/check-display-content';
|
|
1
3
|
function isValidEntry(entry) {
|
|
2
4
|
return entry.isIntersecting && entry.intersectionRect.width > 0 && entry.intersectionRect.height > 0;
|
|
3
5
|
}
|
|
@@ -15,6 +17,13 @@ export function createIntersectionObserver({
|
|
|
15
17
|
entries.forEach(entry => {
|
|
16
18
|
var _mutationTag;
|
|
17
19
|
if (!(entry.target instanceof HTMLElement) || !isValidEntry(entry)) {
|
|
20
|
+
// TODO: Remove this logic when analysis is complete
|
|
21
|
+
if (fg('platform_ufo_display_content_resolution_ttvc_v3')) {
|
|
22
|
+
if (entry.target instanceof HTMLElement && !isValidEntry(entry) && checkedChildrenCache.get(entry.target) === false) {
|
|
23
|
+
incrementCheckedInvalidChildrenCount();
|
|
24
|
+
checkedChildrenCache.set(entry.target, true);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
18
27
|
return;
|
|
19
28
|
}
|
|
20
29
|
let mutationTag = null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// TODO: Remove this cache when analysis is complete - it is used to track whether direct children elements will be ignored by the observer
|
|
2
|
+
export const checkedChildrenCache = new WeakMap();
|
|
3
|
+
let checkedInvalidChildrenCount = 0;
|
|
4
|
+
export function incrementCheckedInvalidChildrenCount() {
|
|
5
|
+
checkedInvalidChildrenCount++;
|
|
6
|
+
}
|
|
7
|
+
export function getInvalidChildrenCount() {
|
|
8
|
+
return checkedInvalidChildrenCount;
|
|
9
|
+
}
|
|
10
|
+
export default function checkCssProperty(element) {
|
|
11
|
+
const computedStyle = window.getComputedStyle(element);
|
|
12
|
+
if (computedStyle.display === 'contents') {
|
|
13
|
+
// If display is 'contents', we return the direct children of the element
|
|
14
|
+
const result = [];
|
|
15
|
+
for (const child of element.children) {
|
|
16
|
+
if (child instanceof HTMLElement) {
|
|
17
|
+
if (!checkedChildrenCache.has(child)) {
|
|
18
|
+
// TODO: Remove this cache when analysis is complete
|
|
19
|
+
checkedChildrenCache.set(child, false);
|
|
20
|
+
}
|
|
21
|
+
result.push(child);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
return [element];
|
|
27
|
+
}
|
|
@@ -11,6 +11,7 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
|
|
|
11
11
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
12
12
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
13
13
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
14
|
+
import { getInvalidChildrenCount } from '../viewport-observer/utils/check-display-content';
|
|
14
15
|
import { calculateTTVCPercentilesWithDebugInfo } from './percentile-calc';
|
|
15
16
|
import getViewportHeight from './utils/get-viewport-height';
|
|
16
17
|
import getViewportWidth from './utils/get-viewport-width';
|
|
@@ -349,8 +350,11 @@ var AbstractVCCalculatorBase = /*#__PURE__*/function () {
|
|
|
349
350
|
vcDetails: vcDetails !== null && vcDetails !== void 0 ? vcDetails : undefined
|
|
350
351
|
};
|
|
351
352
|
result.ratios = this.calculateRatios(filteredEntries);
|
|
353
|
+
if (fg('platform_ufo_display_content_resolution_ttvc_v3')) {
|
|
354
|
+
result.childrenIgnoredCount = getInvalidChildrenCount();
|
|
355
|
+
}
|
|
352
356
|
return _context2.abrupt("return", result);
|
|
353
|
-
case
|
|
357
|
+
case 14:
|
|
354
358
|
case "end":
|
|
355
359
|
return _context2.stop();
|
|
356
360
|
}
|
|
@@ -13,6 +13,7 @@ import { RLLPlaceholderHandlers } from '../../vc-observer/observers/rll-placehol
|
|
|
13
13
|
import { createIntersectionObserver } from './intersection-observer';
|
|
14
14
|
import createMutationObserver from './mutation-observer';
|
|
15
15
|
import createPerformanceObserver from './performance-observer';
|
|
16
|
+
import checkCssProperty from './utils/check-display-content';
|
|
16
17
|
import checkWithinComponent, { cleanupCaches } from './utils/check-within-component';
|
|
17
18
|
import isInVCIgnoreIfNoLayoutShiftMarker from './utils/is-in-vc-ignore-if-no-layout-shift-marker';
|
|
18
19
|
function isElementVisible(element) {
|
|
@@ -114,8 +115,7 @@ var ViewportObserver = /*#__PURE__*/function () {
|
|
|
114
115
|
_iterator = _createForOfIteratorHelper(addedNodes);
|
|
115
116
|
_context2.prev = 4;
|
|
116
117
|
_loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
|
|
117
|
-
var _this$intersectionObs9;
|
|
118
|
-
var addedNodeRef, addedNode, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, _this$intersectionObs3, result, _this$intersectionObs4, _result, _this$intersectionObs5, sameDeletedNode, isInIgnoreLsMarker, _this$intersectionObs6, _this$intersectionObs7, _checkWithinComponent, isWithinThirdPartySegment, _this$intersectionObs8;
|
|
118
|
+
var addedNodeRef, addedNode, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, _this$intersectionObs3, result, _this$intersectionObs4, _result, _this$intersectionObs5, sameDeletedNode, isInIgnoreLsMarker, _this$intersectionObs6, _this$intersectionObs7, _checkWithinComponent, isWithinThirdPartySegment, _this$intersectionObs8, validTargets, _iterator2, _step2, _this$intersectionObs9, validTarget, _this$intersectionObs0;
|
|
119
119
|
return _regeneratorRuntime.wrap(function _loop$(_context) {
|
|
120
120
|
while (1) switch (_context.prev = _context.next) {
|
|
121
121
|
case 0:
|
|
@@ -245,7 +245,23 @@ var ViewportObserver = /*#__PURE__*/function () {
|
|
|
245
245
|
(_this$intersectionObs8 = _this.intersectionObserver) === null || _this$intersectionObs8 === void 0 || _this$intersectionObs8.watchAndTag(addedNode, 'mutation:third-party-element');
|
|
246
246
|
return _context.abrupt("return", 0);
|
|
247
247
|
case 54:
|
|
248
|
-
|
|
248
|
+
if (fg('platform_ufo_display_content_resolution_ttvc_v3')) {
|
|
249
|
+
// Check if the target has display:content css property, return array of valid targets
|
|
250
|
+
validTargets = checkCssProperty(addedNode);
|
|
251
|
+
_iterator2 = _createForOfIteratorHelper(validTargets);
|
|
252
|
+
try {
|
|
253
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
254
|
+
validTarget = _step2.value;
|
|
255
|
+
(_this$intersectionObs9 = _this.intersectionObserver) === null || _this$intersectionObs9 === void 0 || _this$intersectionObs9.watchAndTag(validTarget, createElementMutationsWatcher(removedNodeRects));
|
|
256
|
+
}
|
|
257
|
+
} catch (err) {
|
|
258
|
+
_iterator2.e(err);
|
|
259
|
+
} finally {
|
|
260
|
+
_iterator2.f();
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
(_this$intersectionObs0 = _this.intersectionObserver) === null || _this$intersectionObs0 === void 0 || _this$intersectionObs0.watchAndTag(addedNode, createElementMutationsWatcher(removedNodeRects));
|
|
264
|
+
}
|
|
249
265
|
case 55:
|
|
250
266
|
case "end":
|
|
251
267
|
return _context.stop();
|
|
@@ -291,12 +307,12 @@ var ViewportObserver = /*#__PURE__*/function () {
|
|
|
291
307
|
};
|
|
292
308
|
}());
|
|
293
309
|
_defineProperty(this, "handleAttributeMutation", function (_ref6) {
|
|
294
|
-
var _this$
|
|
310
|
+
var _this$intersectionObs1;
|
|
295
311
|
var target = _ref6.target,
|
|
296
312
|
attributeName = _ref6.attributeName,
|
|
297
313
|
oldValue = _ref6.oldValue,
|
|
298
314
|
newValue = _ref6.newValue;
|
|
299
|
-
(_this$
|
|
315
|
+
(_this$intersectionObs1 = _this.intersectionObserver) === null || _this$intersectionObs1 === void 0 || _this$intersectionObs1.watchAndTag(target, function (_ref7) {
|
|
300
316
|
var target = _ref7.target,
|
|
301
317
|
rect = _ref7.rect;
|
|
302
318
|
if (isContainedWithinMediaWrapper(target)) {
|
|
@@ -359,11 +375,11 @@ var ViewportObserver = /*#__PURE__*/function () {
|
|
|
359
375
|
_defineProperty(this, "handleLayoutShift", function (_ref8) {
|
|
360
376
|
var time = _ref8.time,
|
|
361
377
|
changedRects = _ref8.changedRects;
|
|
362
|
-
var
|
|
363
|
-
|
|
378
|
+
var _iterator3 = _createForOfIteratorHelper(changedRects),
|
|
379
|
+
_step3;
|
|
364
380
|
try {
|
|
365
|
-
for (
|
|
366
|
-
var changedRect =
|
|
381
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
382
|
+
var changedRect = _step3.value;
|
|
367
383
|
var target = changedRect.node;
|
|
368
384
|
if (target) {
|
|
369
385
|
_this.onChange({
|
|
@@ -377,9 +393,9 @@ var ViewportObserver = /*#__PURE__*/function () {
|
|
|
377
393
|
}
|
|
378
394
|
}
|
|
379
395
|
} catch (err) {
|
|
380
|
-
|
|
396
|
+
_iterator3.e(err);
|
|
381
397
|
} finally {
|
|
382
|
-
|
|
398
|
+
_iterator3.f();
|
|
383
399
|
}
|
|
384
400
|
});
|
|
385
401
|
this.mapVisibleNodeRects = new WeakMap();
|
|
@@ -436,12 +452,12 @@ var ViewportObserver = /*#__PURE__*/function () {
|
|
|
436
452
|
}, {
|
|
437
453
|
key: "stop",
|
|
438
454
|
value: function stop() {
|
|
439
|
-
var _this$mutationObserve2, _this$
|
|
455
|
+
var _this$mutationObserve2, _this$intersectionObs10, _this$performanceObse2;
|
|
440
456
|
if (!this.isStarted) {
|
|
441
457
|
return;
|
|
442
458
|
}
|
|
443
459
|
(_this$mutationObserve2 = this.mutationObserver) === null || _this$mutationObserve2 === void 0 || _this$mutationObserve2.disconnect();
|
|
444
|
-
(_this$
|
|
460
|
+
(_this$intersectionObs10 = this.intersectionObserver) === null || _this$intersectionObs10 === void 0 || _this$intersectionObs10.disconnect();
|
|
445
461
|
(_this$performanceObse2 = this.performanceObserver) === null || _this$performanceObse2 === void 0 || _this$performanceObse2.disconnect();
|
|
446
462
|
this.isStarted = false;
|
|
447
463
|
// Clean up caches when stopping
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
import { checkedChildrenCache, incrementCheckedInvalidChildrenCount } from '../utils/check-display-content';
|
|
1
3
|
function isValidEntry(entry) {
|
|
2
4
|
return entry.isIntersecting && entry.intersectionRect.width > 0 && entry.intersectionRect.height > 0;
|
|
3
5
|
}
|
|
@@ -13,6 +15,13 @@ export function createIntersectionObserver(_ref) {
|
|
|
13
15
|
var startTime = performance.now();
|
|
14
16
|
entries.forEach(function (entry) {
|
|
15
17
|
if (!(entry.target instanceof HTMLElement) || !isValidEntry(entry)) {
|
|
18
|
+
// TODO: Remove this logic when analysis is complete
|
|
19
|
+
if (fg('platform_ufo_display_content_resolution_ttvc_v3')) {
|
|
20
|
+
if (entry.target instanceof HTMLElement && !isValidEntry(entry) && checkedChildrenCache.get(entry.target) === false) {
|
|
21
|
+
incrementCheckedInvalidChildrenCount();
|
|
22
|
+
checkedChildrenCache.set(entry.target, true);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
16
25
|
return;
|
|
17
26
|
}
|
|
18
27
|
var mutationTag = null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
|
+
// TODO: Remove this cache when analysis is complete - it is used to track whether direct children elements will be ignored by the observer
|
|
5
|
+
export var checkedChildrenCache = new WeakMap();
|
|
6
|
+
var checkedInvalidChildrenCount = 0;
|
|
7
|
+
export function incrementCheckedInvalidChildrenCount() {
|
|
8
|
+
checkedInvalidChildrenCount++;
|
|
9
|
+
}
|
|
10
|
+
export function getInvalidChildrenCount() {
|
|
11
|
+
return checkedInvalidChildrenCount;
|
|
12
|
+
}
|
|
13
|
+
export default function checkCssProperty(element) {
|
|
14
|
+
var computedStyle = window.getComputedStyle(element);
|
|
15
|
+
if (computedStyle.display === 'contents') {
|
|
16
|
+
// If display is 'contents', we return the direct children of the element
|
|
17
|
+
var result = [];
|
|
18
|
+
var _iterator = _createForOfIteratorHelper(element.children),
|
|
19
|
+
_step;
|
|
20
|
+
try {
|
|
21
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
22
|
+
var child = _step.value;
|
|
23
|
+
if (child instanceof HTMLElement) {
|
|
24
|
+
if (!checkedChildrenCache.has(child)) {
|
|
25
|
+
// TODO: Remove this cache when analysis is complete
|
|
26
|
+
checkedChildrenCache.set(child, false);
|
|
27
|
+
}
|
|
28
|
+
result.push(child);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
_iterator.e(err);
|
|
33
|
+
} finally {
|
|
34
|
+
_iterator.f();
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
return [element];
|
|
39
|
+
}
|
|
@@ -115,6 +115,7 @@ export type RevisionPayloadEntry = {
|
|
|
115
115
|
vcDetails?: RevisionPayloadVCDetails;
|
|
116
116
|
ratios?: VCRatioType;
|
|
117
117
|
abortReason?: VCAbortReason | null;
|
|
118
|
+
childrenIgnoredCount?: number;
|
|
118
119
|
};
|
|
119
120
|
export type RevisionPayload = RevisionPayloadEntry[];
|
|
120
121
|
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const checkedChildrenCache: WeakMap<HTMLElement, boolean>;
|
|
2
|
+
export declare function incrementCheckedInvalidChildrenCount(): void;
|
|
3
|
+
export declare function getInvalidChildrenCount(): number;
|
|
4
|
+
export default function checkCssProperty(element: HTMLElement): Element[];
|
|
@@ -115,6 +115,7 @@ export type RevisionPayloadEntry = {
|
|
|
115
115
|
vcDetails?: RevisionPayloadVCDetails;
|
|
116
116
|
ratios?: VCRatioType;
|
|
117
117
|
abortReason?: VCAbortReason | null;
|
|
118
|
+
childrenIgnoredCount?: number;
|
|
118
119
|
};
|
|
119
120
|
export type RevisionPayload = RevisionPayloadEntry[];
|
|
120
121
|
export {};
|
package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/utils/check-display-content.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const checkedChildrenCache: WeakMap<HTMLElement, boolean>;
|
|
2
|
+
export declare function incrementCheckedInvalidChildrenCount(): void;
|
|
3
|
+
export declare function getInvalidChildrenCount(): number;
|
|
4
|
+
export default function checkCssProperty(element: HTMLElement): Element[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/react-ufo",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.2",
|
|
4
4
|
"description": "Parts of React UFO that are publicly available",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -197,6 +197,9 @@
|
|
|
197
197
|
},
|
|
198
198
|
"platform_ufo_send_vc_100": {
|
|
199
199
|
"type": "boolean"
|
|
200
|
+
},
|
|
201
|
+
"platform_ufo_display_content_resolution_ttvc_v3": {
|
|
202
|
+
"type": "boolean"
|
|
200
203
|
}
|
|
201
204
|
}
|
|
202
205
|
}
|