@atlaskit/react-ufo 4.15.4 → 4.15.5

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 (26) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/index.js +7 -0
  3. package/dist/cjs/vc/vc-observer-new/metric-calculator/vcnext/index.js +4 -1
  4. package/dist/cjs/vc/vc-observer-new/viewport-observer/index.js +290 -191
  5. package/dist/cjs/vc/vc-observer-new/viewport-observer/intersection-observer/index.js +45 -2
  6. package/dist/cjs/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.js +15 -4
  7. package/dist/cjs/vc/vc-observer-new/viewport-observer/utils/is-zero-dimension-rectangle.js +9 -0
  8. package/dist/es2019/vc/vc-observer/observers/ssr-placeholders/index.js +5 -0
  9. package/dist/es2019/vc/vc-observer-new/metric-calculator/vcnext/index.js +4 -1
  10. package/dist/es2019/vc/vc-observer-new/viewport-observer/index.js +158 -81
  11. package/dist/es2019/vc/vc-observer-new/viewport-observer/intersection-observer/index.js +33 -2
  12. package/dist/es2019/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.js +15 -4
  13. package/dist/es2019/vc/vc-observer-new/viewport-observer/utils/is-zero-dimension-rectangle.js +3 -0
  14. package/dist/esm/vc/vc-observer/observers/ssr-placeholders/index.js +7 -0
  15. package/dist/esm/vc/vc-observer-new/metric-calculator/vcnext/index.js +4 -1
  16. package/dist/esm/vc/vc-observer-new/viewport-observer/index.js +288 -189
  17. package/dist/esm/vc/vc-observer-new/viewport-observer/intersection-observer/index.js +45 -2
  18. package/dist/esm/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.js +15 -4
  19. package/dist/esm/vc/vc-observer-new/viewport-observer/utils/is-zero-dimension-rectangle.js +3 -0
  20. package/dist/types/vc/vc-observer/observers/ssr-placeholders/index.d.ts +1 -0
  21. package/dist/types/vc/vc-observer-new/types.d.ts +1 -1
  22. package/dist/types/vc/vc-observer-new/viewport-observer/utils/is-zero-dimension-rectangle.d.ts +1 -0
  23. package/dist/types-ts4.5/vc/vc-observer/observers/ssr-placeholders/index.d.ts +1 -0
  24. package/dist/types-ts4.5/vc/vc-observer-new/types.d.ts +1 -1
  25. package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/utils/is-zero-dimension-rectangle.d.ts +1 -0
  26. package/package.json +7 -1
@@ -41,21 +41,85 @@ var createElementMutationsWatcher = function createElementMutationsWatcher(remov
41
41
  return 'mutation:element';
42
42
  };
43
43
  };
44
+ var createElementMutationsWatcherV4 = function createElementMutationsWatcherV4(removedNodeRects, isWithinThirdPartySegment, hasSameDeletedNode, timestamp, isTargetReactRoot, getSSRState, getSSRPlaceholderHandler) {
45
+ return function (_ref2) {
46
+ var target = _ref2.target,
47
+ rect = _ref2.rect;
48
+ if (getSSRState) {
49
+ var ssrState = getSSRState();
50
+ var SSRStateEnum = {
51
+ normal: 1,
52
+ waitingForFirstRender: 2,
53
+ ignoring: 3
54
+ };
55
+ if (ssrState.state === SSRStateEnum.waitingForFirstRender && timestamp > ssrState.renderStart && isTargetReactRoot) {
56
+ ssrState.state = SSRStateEnum.ignoring;
57
+ if (ssrState.renderStop === -1) {
58
+ // arbitrary 500ms DOM update window
59
+ ssrState.renderStop = timestamp + 500;
60
+ }
61
+ return 'ssr-hydration';
62
+ }
63
+ if (ssrState.state === SSRStateEnum.ignoring && timestamp > ssrState.renderStart && isTargetReactRoot) {
64
+ if (timestamp <= ssrState.renderStop) {
65
+ return 'ssr-hydration';
66
+ } else {
67
+ ssrState.state = SSRStateEnum.normal;
68
+ }
69
+ }
70
+ }
71
+ if (getSSRPlaceholderHandler) {
72
+ var ssrPlaceholderHandler = getSSRPlaceholderHandler();
73
+ if (ssrPlaceholderHandler) {
74
+ if ((ssrPlaceholderHandler.isPlaceholder(target) || ssrPlaceholderHandler.isPlaceholderIgnored(target)) && ssrPlaceholderHandler.checkIfExistedAndSizeMatchingV3(target)) {
75
+ return 'mutation:ssr-placeholder';
76
+ }
77
+ if ((ssrPlaceholderHandler.isPlaceholderReplacement(target) || ssrPlaceholderHandler.isPlaceholderIgnored(target)) && ssrPlaceholderHandler.validateReactComponentMatchToPlaceholderV4(target)) {
78
+ return 'mutation:ssr-placeholder';
79
+ }
80
+ }
81
+ }
82
+ if (hasSameDeletedNode && isInVCIgnoreIfNoLayoutShiftMarker(target)) {
83
+ return 'mutation:remount';
84
+ }
85
+ if (isContainedWithinMediaWrapper(target)) {
86
+ return 'mutation:media';
87
+ }
88
+ if (isWithinThirdPartySegment) {
89
+ return 'mutation:third-party-element';
90
+ }
91
+ var isInIgnoreLsMarker = isInVCIgnoreIfNoLayoutShiftMarker(target);
92
+ if (!isInIgnoreLsMarker) {
93
+ return 'mutation:element';
94
+ }
95
+ var isRLLPlaceholder = RLLPlaceholderHandlers.getInstance().isRLLPlaceholderHydration(rect);
96
+ if (isRLLPlaceholder && isInIgnoreLsMarker) {
97
+ return 'mutation:rll-placeholder';
98
+ }
99
+ var wasDeleted = removedNodeRects.some(function (nr) {
100
+ return isSameRectDimensions(nr, rect);
101
+ });
102
+ if (wasDeleted && isInIgnoreLsMarker) {
103
+ return 'mutation:element-replacement';
104
+ }
105
+ return 'mutation:element';
106
+ };
107
+ };
44
108
  var ViewportObserver = /*#__PURE__*/function () {
45
109
  // SSR context functions
46
110
 
47
- function ViewportObserver(_ref2) {
111
+ function ViewportObserver(_ref3) {
48
112
  var _this = this;
49
- var onChange = _ref2.onChange,
50
- getSSRState = _ref2.getSSRState,
51
- getSSRPlaceholderHandler = _ref2.getSSRPlaceholderHandler;
113
+ var onChange = _ref3.onChange,
114
+ getSSRState = _ref3.getSSRState,
115
+ getSSRPlaceholderHandler = _ref3.getSSRPlaceholderHandler;
52
116
  _classCallCheck(this, ViewportObserver);
53
- _defineProperty(this, "handleIntersectionEntry", function (_ref3) {
54
- var target = _ref3.target,
55
- rect = _ref3.rect,
56
- time = _ref3.time,
57
- type = _ref3.type,
58
- mutationData = _ref3.mutationData;
117
+ _defineProperty(this, "handleIntersectionEntry", function (_ref4) {
118
+ var target = _ref4.target,
119
+ rect = _ref4.rect,
120
+ time = _ref4.time,
121
+ type = _ref4.type,
122
+ mutationData = _ref4.mutationData;
59
123
  if (!target) {
60
124
  return;
61
125
  }
@@ -73,12 +137,12 @@ var ViewportObserver = /*#__PURE__*/function () {
73
137
  });
74
138
  });
75
139
  _defineProperty(this, "handleChildListMutation", /*#__PURE__*/function () {
76
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref4) {
77
- var target, addedNodes, removedNodes, timestamp, removedNodeRects, targetNode, _iterator, _step, addedNodeRef, addedNode, _iterator2, _step2, _loop, _ret;
78
- return _regeneratorRuntime.wrap(function _callee$(_context2) {
79
- while (1) switch (_context2.prev = _context2.next) {
140
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref5) {
141
+ var target, addedNodes, removedNodes, timestamp, removedNodeRects, targetNode, _iterator, _step, _loop;
142
+ return _regeneratorRuntime.wrap(function _callee$(_context3) {
143
+ while (1) switch (_context3.prev = _context3.next) {
80
144
  case 0:
81
- target = _ref4.target, addedNodes = _ref4.addedNodes, removedNodes = _ref4.removedNodes, timestamp = _ref4.timestamp;
145
+ target = _ref5.target, addedNodes = _ref5.addedNodes, removedNodes = _ref5.removedNodes, timestamp = _ref5.timestamp;
82
146
  removedNodeRects = removedNodes.map(function (ref) {
83
147
  var n = ref.deref();
84
148
  if (!n) {
@@ -88,203 +152,238 @@ var ViewportObserver = /*#__PURE__*/function () {
88
152
  });
89
153
  targetNode = target.deref();
90
154
  _iterator = _createForOfIteratorHelper(addedNodes);
91
- _context2.prev = 4;
92
- _iterator.s();
93
- case 6:
94
- if ((_step = _iterator.n()).done) {
95
- _context2.next = 32;
96
- break;
97
- }
98
- addedNodeRef = _step.value;
99
- addedNode = addedNodeRef.deref();
100
- if (addedNode) {
101
- _context2.next = 11;
102
- break;
103
- }
104
- return _context2.abrupt("continue", 30);
105
- case 11:
106
- _iterator2 = _createForOfIteratorHelper(getMutatedElements(addedNode));
107
- _context2.prev = 12;
155
+ _context3.prev = 4;
108
156
  _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
109
- var _step2$value, isDisplayContentsElementChildren, element, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, _this$intersectionObs3, result, _this$intersectionObs4, sameDeletedNode, isInIgnoreLsMarker, _this$intersectionObs5, _this$intersectionObs6, _ref6, isWithinThirdPartySegment, _this$intersectionObs7, _this$intersectionObs8, _this$intersectionObs9;
110
- return _regeneratorRuntime.wrap(function _loop$(_context) {
111
- while (1) switch (_context.prev = _context.next) {
157
+ var addedNodeRef, addedNode, _this$getSSRState, _this$intersectionObs, hasSameDeletedNode, _checkWithinComponent, isWithinThirdPartySegment, isTargetReactRoot, _iterator2, _step2, _loop2, _ret;
158
+ return _regeneratorRuntime.wrap(function _loop$(_context2) {
159
+ while (1) switch (_context2.prev = _context2.next) {
112
160
  case 0:
113
- _step2$value = _step2.value, isDisplayContentsElementChildren = _step2$value.isDisplayContentsElementChildren, element = _step2$value.element;
114
- if (!_this.getSSRState) {
115
- _context.next = 16;
116
- break;
117
- }
118
- ssrState = _this.getSSRState();
119
- SSRStateEnum = {
120
- normal: 1,
121
- waitingForFirstRender: 2,
122
- ignoring: 3
123
- };
124
- if (!(ssrState.state === SSRStateEnum.waitingForFirstRender && timestamp > ssrState.renderStart && targetNode === ssrState.reactRootElement)) {
125
- _context.next = 9;
126
- break;
127
- }
128
- ssrState.state = SSRStateEnum.ignoring;
129
- if (ssrState.renderStop === -1) {
130
- // arbitrary 500ms DOM update window
131
- ssrState.renderStop = timestamp + 500;
132
- }
133
- (_this$intersectionObs = _this.intersectionObserver) === null || _this$intersectionObs === void 0 || _this$intersectionObs.watchAndTag(element, 'ssr-hydration');
134
- return _context.abrupt("return", 0);
135
- case 9:
136
- if (!(ssrState.state === SSRStateEnum.ignoring && timestamp > ssrState.renderStart && targetNode === ssrState.reactRootElement)) {
137
- _context.next = 16;
138
- break;
139
- }
140
- if (!(timestamp <= ssrState.renderStop)) {
141
- _context.next = 15;
142
- break;
143
- }
144
- (_this$intersectionObs2 = _this.intersectionObserver) === null || _this$intersectionObs2 === void 0 || _this$intersectionObs2.watchAndTag(element, 'ssr-hydration');
145
- return _context.abrupt("return", 0);
146
- case 15:
147
- ssrState.state = SSRStateEnum.normal;
148
- case 16:
149
- if (!_this.getSSRPlaceholderHandler) {
150
- _context.next = 30;
151
- break;
152
- }
153
- ssrPlaceholderHandler = _this.getSSRPlaceholderHandler();
154
- if (!ssrPlaceholderHandler) {
155
- _context.next = 30;
156
- break;
157
- }
158
- if (!(ssrPlaceholderHandler.isPlaceholder(element) || ssrPlaceholderHandler.isPlaceholderIgnored(element))) {
159
- _context.next = 23;
160
- break;
161
- }
162
- if (!ssrPlaceholderHandler.checkIfExistedAndSizeMatchingV3(element)) {
163
- _context.next = 23;
164
- break;
165
- }
166
- (_this$intersectionObs3 = _this.intersectionObserver) === null || _this$intersectionObs3 === void 0 || _this$intersectionObs3.watchAndTag(element, 'mutation:ssr-placeholder');
167
- return _context.abrupt("return", 0);
168
- case 23:
169
- if (!(ssrPlaceholderHandler.isPlaceholderReplacement(element) || ssrPlaceholderHandler.isPlaceholderIgnored(element))) {
170
- _context.next = 30;
161
+ addedNodeRef = _step.value;
162
+ addedNode = addedNodeRef.deref();
163
+ if (addedNode) {
164
+ _context2.next = 4;
171
165
  break;
172
166
  }
173
- _context.next = 26;
174
- return ssrPlaceholderHandler.validateReactComponentMatchToPlaceholder(element);
175
- case 26:
176
- result = _context.sent;
177
- if (!(result !== false)) {
178
- _context.next = 30;
167
+ return _context2.abrupt("return", 1);
168
+ case 4:
169
+ if (!fg('platform_ufo_detect_zero_dimension_rectangles')) {
170
+ _context2.next = 11;
179
171
  break;
180
172
  }
181
- (_this$intersectionObs4 = _this.intersectionObserver) === null || _this$intersectionObs4 === void 0 || _this$intersectionObs4.watchAndTag(element, 'mutation:ssr-placeholder');
182
- return _context.abrupt("return", 0);
183
- case 30:
184
- sameDeletedNode = removedNodes.find(function (ref) {
173
+ hasSameDeletedNode = removedNodes.find(function (ref) {
185
174
  var n = ref.deref();
186
- if (!n || !element) {
175
+ if (!n || !addedNode) {
187
176
  return false;
188
177
  }
189
- return n.isEqualNode(element);
178
+ return n.isEqualNode(addedNode);
190
179
  });
191
- isInIgnoreLsMarker = element instanceof HTMLElement ? isInVCIgnoreIfNoLayoutShiftMarker(element) : false;
192
- if (!(sameDeletedNode && isInIgnoreLsMarker)) {
193
- _context.next = 35;
194
- break;
195
- }
196
- (_this$intersectionObs5 = _this.intersectionObserver) === null || _this$intersectionObs5 === void 0 || _this$intersectionObs5.watchAndTag(element, 'mutation:remount');
197
- return _context.abrupt("return", 0);
198
- case 35:
199
- if (!isContainedWithinMediaWrapper(element)) {
200
- _context.next = 38;
180
+ _checkWithinComponent = checkWithinComponent(addedNode, 'UFOThirdPartySegment', _this.mapIs3pResult), isWithinThirdPartySegment = _checkWithinComponent.isWithin;
181
+ isTargetReactRoot = targetNode === ((_this$getSSRState = _this.getSSRState) === null || _this$getSSRState === void 0 || (_this$getSSRState = _this$getSSRState.call(_this)) === null || _this$getSSRState === void 0 ? void 0 : _this$getSSRState.reactRootElement);
182
+ (_this$intersectionObs = _this.intersectionObserver) === null || _this$intersectionObs === void 0 || _this$intersectionObs.watchAndTag(addedNode, createElementMutationsWatcherV4(removedNodeRects, isWithinThirdPartySegment, !!hasSameDeletedNode, timestamp, isTargetReactRoot, _this.getSSRState, _this.getSSRPlaceholderHandler));
183
+ _context2.next = 30;
184
+ break;
185
+ case 11:
186
+ _iterator2 = _createForOfIteratorHelper(getMutatedElements(addedNode));
187
+ _context2.prev = 12;
188
+ _loop2 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop2() {
189
+ var _step2$value, isDisplayContentsElementChildren, element, ssrState, SSRStateEnum, _this$intersectionObs2, _this$intersectionObs3, ssrPlaceholderHandler, _this$intersectionObs4, result, _this$intersectionObs5, sameDeletedNode, isInIgnoreLsMarker, _this$intersectionObs6, _this$intersectionObs7, _ref7, isWithinThirdPartySegment, _this$intersectionObs8, _this$intersectionObs9, _this$intersectionObs0;
190
+ return _regeneratorRuntime.wrap(function _loop2$(_context) {
191
+ while (1) switch (_context.prev = _context.next) {
192
+ case 0:
193
+ _step2$value = _step2.value, isDisplayContentsElementChildren = _step2$value.isDisplayContentsElementChildren, element = _step2$value.element;
194
+ if (!_this.getSSRState) {
195
+ _context.next = 16;
196
+ break;
197
+ }
198
+ ssrState = _this.getSSRState();
199
+ SSRStateEnum = {
200
+ normal: 1,
201
+ waitingForFirstRender: 2,
202
+ ignoring: 3
203
+ };
204
+ if (!(ssrState.state === SSRStateEnum.waitingForFirstRender && timestamp > ssrState.renderStart && targetNode === ssrState.reactRootElement)) {
205
+ _context.next = 9;
206
+ break;
207
+ }
208
+ ssrState.state = SSRStateEnum.ignoring;
209
+ if (ssrState.renderStop === -1) {
210
+ // arbitrary 500ms DOM update window
211
+ ssrState.renderStop = timestamp + 500;
212
+ }
213
+ (_this$intersectionObs2 = _this.intersectionObserver) === null || _this$intersectionObs2 === void 0 || _this$intersectionObs2.watchAndTag(element, 'ssr-hydration');
214
+ return _context.abrupt("return", 0);
215
+ case 9:
216
+ if (!(ssrState.state === SSRStateEnum.ignoring && timestamp > ssrState.renderStart && targetNode === ssrState.reactRootElement)) {
217
+ _context.next = 16;
218
+ break;
219
+ }
220
+ if (!(timestamp <= ssrState.renderStop)) {
221
+ _context.next = 15;
222
+ break;
223
+ }
224
+ (_this$intersectionObs3 = _this.intersectionObserver) === null || _this$intersectionObs3 === void 0 || _this$intersectionObs3.watchAndTag(element, 'ssr-hydration');
225
+ return _context.abrupt("return", 0);
226
+ case 15:
227
+ ssrState.state = SSRStateEnum.normal;
228
+ case 16:
229
+ if (!_this.getSSRPlaceholderHandler) {
230
+ _context.next = 30;
231
+ break;
232
+ }
233
+ ssrPlaceholderHandler = _this.getSSRPlaceholderHandler();
234
+ if (!ssrPlaceholderHandler) {
235
+ _context.next = 30;
236
+ break;
237
+ }
238
+ if (!(ssrPlaceholderHandler.isPlaceholder(element) || ssrPlaceholderHandler.isPlaceholderIgnored(element))) {
239
+ _context.next = 23;
240
+ break;
241
+ }
242
+ if (!ssrPlaceholderHandler.checkIfExistedAndSizeMatchingV3(element)) {
243
+ _context.next = 23;
244
+ break;
245
+ }
246
+ (_this$intersectionObs4 = _this.intersectionObserver) === null || _this$intersectionObs4 === void 0 || _this$intersectionObs4.watchAndTag(element, 'mutation:ssr-placeholder');
247
+ return _context.abrupt("return", 0);
248
+ case 23:
249
+ if (!(ssrPlaceholderHandler.isPlaceholderReplacement(element) || ssrPlaceholderHandler.isPlaceholderIgnored(element))) {
250
+ _context.next = 30;
251
+ break;
252
+ }
253
+ _context.next = 26;
254
+ return ssrPlaceholderHandler.validateReactComponentMatchToPlaceholder(element);
255
+ case 26:
256
+ result = _context.sent;
257
+ if (!(result !== false)) {
258
+ _context.next = 30;
259
+ break;
260
+ }
261
+ (_this$intersectionObs5 = _this.intersectionObserver) === null || _this$intersectionObs5 === void 0 || _this$intersectionObs5.watchAndTag(element, 'mutation:ssr-placeholder');
262
+ return _context.abrupt("return", 0);
263
+ case 30:
264
+ sameDeletedNode = removedNodes.find(function (ref) {
265
+ var n = ref.deref();
266
+ if (!n || !element) {
267
+ return false;
268
+ }
269
+ return n.isEqualNode(element);
270
+ });
271
+ isInIgnoreLsMarker = element instanceof HTMLElement ? isInVCIgnoreIfNoLayoutShiftMarker(element) : false;
272
+ if (!(sameDeletedNode && isInIgnoreLsMarker)) {
273
+ _context.next = 35;
274
+ break;
275
+ }
276
+ (_this$intersectionObs6 = _this.intersectionObserver) === null || _this$intersectionObs6 === void 0 || _this$intersectionObs6.watchAndTag(element, 'mutation:remount');
277
+ return _context.abrupt("return", 0);
278
+ case 35:
279
+ if (!isContainedWithinMediaWrapper(element)) {
280
+ _context.next = 38;
281
+ break;
282
+ }
283
+ (_this$intersectionObs7 = _this.intersectionObserver) === null || _this$intersectionObs7 === void 0 || _this$intersectionObs7.watchAndTag(element, 'mutation:media');
284
+ return _context.abrupt("return", 0);
285
+ case 38:
286
+ _ref7 = element instanceof HTMLElement ? checkWithinComponent(element, 'UFOThirdPartySegment', _this.mapIs3pResult) : {
287
+ isWithin: false
288
+ }, isWithinThirdPartySegment = _ref7.isWithin;
289
+ if (!isWithinThirdPartySegment) {
290
+ _context.next = 42;
291
+ break;
292
+ }
293
+ (_this$intersectionObs8 = _this.intersectionObserver) === null || _this$intersectionObs8 === void 0 || _this$intersectionObs8.watchAndTag(element, 'mutation:third-party-element');
294
+ return _context.abrupt("return", 0);
295
+ case 42:
296
+ if (isDisplayContentsElementChildren) {
297
+ (_this$intersectionObs9 = _this.intersectionObserver) === null || _this$intersectionObs9 === void 0 || _this$intersectionObs9.watchAndTag(element, 'mutation:display-contents-children-element');
298
+ } else {
299
+ (_this$intersectionObs0 = _this.intersectionObserver) === null || _this$intersectionObs0 === void 0 || _this$intersectionObs0.watchAndTag(element, createElementMutationsWatcher(removedNodeRects));
300
+ }
301
+ case 43:
302
+ case "end":
303
+ return _context.stop();
304
+ }
305
+ }, _loop2);
306
+ });
307
+ _iterator2.s();
308
+ case 15:
309
+ if ((_step2 = _iterator2.n()).done) {
310
+ _context2.next = 22;
201
311
  break;
202
312
  }
203
- (_this$intersectionObs6 = _this.intersectionObserver) === null || _this$intersectionObs6 === void 0 || _this$intersectionObs6.watchAndTag(element, 'mutation:media');
204
- return _context.abrupt("return", 0);
205
- case 38:
206
- _ref6 = element instanceof HTMLElement ? checkWithinComponent(element, 'UFOThirdPartySegment', _this.mapIs3pResult) : {
207
- isWithin: false
208
- }, isWithinThirdPartySegment = _ref6.isWithin;
209
- if (!isWithinThirdPartySegment) {
210
- _context.next = 42;
313
+ return _context2.delegateYield(_loop2(), "t0", 17);
314
+ case 17:
315
+ _ret = _context2.t0;
316
+ if (!(_ret === 0)) {
317
+ _context2.next = 20;
211
318
  break;
212
319
  }
213
- (_this$intersectionObs7 = _this.intersectionObserver) === null || _this$intersectionObs7 === void 0 || _this$intersectionObs7.watchAndTag(element, 'mutation:third-party-element');
214
- return _context.abrupt("return", 0);
215
- case 42:
216
- if (isDisplayContentsElementChildren) {
217
- (_this$intersectionObs8 = _this.intersectionObserver) === null || _this$intersectionObs8 === void 0 || _this$intersectionObs8.watchAndTag(element, 'mutation:display-contents-children-element');
218
- } else {
219
- (_this$intersectionObs9 = _this.intersectionObserver) === null || _this$intersectionObs9 === void 0 || _this$intersectionObs9.watchAndTag(element, createElementMutationsWatcher(removedNodeRects));
220
- }
221
- case 43:
320
+ return _context2.abrupt("continue", 20);
321
+ case 20:
322
+ _context2.next = 15;
323
+ break;
324
+ case 22:
325
+ _context2.next = 27;
326
+ break;
327
+ case 24:
328
+ _context2.prev = 24;
329
+ _context2.t1 = _context2["catch"](12);
330
+ _iterator2.e(_context2.t1);
331
+ case 27:
332
+ _context2.prev = 27;
333
+ _iterator2.f();
334
+ return _context2.finish(27);
335
+ case 30:
222
336
  case "end":
223
- return _context.stop();
337
+ return _context2.stop();
224
338
  }
225
- }, _loop);
339
+ }, _loop, null, [[12, 24, 27, 30]]);
226
340
  });
227
- _iterator2.s();
228
- case 15:
229
- if ((_step2 = _iterator2.n()).done) {
230
- _context2.next = 22;
341
+ _iterator.s();
342
+ case 7:
343
+ if ((_step = _iterator.n()).done) {
344
+ _context3.next = 13;
231
345
  break;
232
346
  }
233
- return _context2.delegateYield(_loop(), "t0", 17);
234
- case 17:
235
- _ret = _context2.t0;
236
- if (!(_ret === 0)) {
237
- _context2.next = 20;
347
+ return _context3.delegateYield(_loop(), "t0", 9);
348
+ case 9:
349
+ if (!_context3.t0) {
350
+ _context3.next = 11;
238
351
  break;
239
352
  }
240
- return _context2.abrupt("continue", 20);
241
- case 20:
242
- _context2.next = 15;
243
- break;
244
- case 22:
245
- _context2.next = 27;
246
- break;
247
- case 24:
248
- _context2.prev = 24;
249
- _context2.t1 = _context2["catch"](12);
250
- _iterator2.e(_context2.t1);
251
- case 27:
252
- _context2.prev = 27;
253
- _iterator2.f();
254
- return _context2.finish(27);
255
- case 30:
256
- _context2.next = 6;
353
+ return _context3.abrupt("continue", 11);
354
+ case 11:
355
+ _context3.next = 7;
257
356
  break;
258
- case 32:
259
- _context2.next = 37;
357
+ case 13:
358
+ _context3.next = 18;
260
359
  break;
261
- case 34:
262
- _context2.prev = 34;
263
- _context2.t2 = _context2["catch"](4);
264
- _iterator.e(_context2.t2);
265
- case 37:
266
- _context2.prev = 37;
360
+ case 15:
361
+ _context3.prev = 15;
362
+ _context3.t1 = _context3["catch"](4);
363
+ _iterator.e(_context3.t1);
364
+ case 18:
365
+ _context3.prev = 18;
267
366
  _iterator.f();
268
- return _context2.finish(37);
269
- case 40:
367
+ return _context3.finish(18);
368
+ case 21:
270
369
  case "end":
271
- return _context2.stop();
370
+ return _context3.stop();
272
371
  }
273
- }, _callee, null, [[4, 34, 37, 40], [12, 24, 27, 30]]);
372
+ }, _callee, null, [[4, 15, 18, 21]]);
274
373
  }));
275
374
  return function (_x) {
276
- return _ref5.apply(this, arguments);
375
+ return _ref6.apply(this, arguments);
277
376
  };
278
377
  }());
279
- _defineProperty(this, "handleAttributeMutation", function (_ref7) {
280
- var _this$intersectionObs0;
281
- var target = _ref7.target,
282
- attributeName = _ref7.attributeName,
283
- oldValue = _ref7.oldValue,
284
- newValue = _ref7.newValue;
285
- (_this$intersectionObs0 = _this.intersectionObserver) === null || _this$intersectionObs0 === void 0 || _this$intersectionObs0.watchAndTag(target, function (_ref8) {
286
- var target = _ref8.target,
287
- rect = _ref8.rect;
378
+ _defineProperty(this, "handleAttributeMutation", function (_ref8) {
379
+ var _this$intersectionObs1;
380
+ var target = _ref8.target,
381
+ attributeName = _ref8.attributeName,
382
+ oldValue = _ref8.oldValue,
383
+ newValue = _ref8.newValue;
384
+ (_this$intersectionObs1 = _this.intersectionObserver) === null || _this$intersectionObs1 === void 0 || _this$intersectionObs1.watchAndTag(target, function (_ref9) {
385
+ var target = _ref9.target,
386
+ rect = _ref9.rect;
288
387
  if (isContainedWithinMediaWrapper(target)) {
289
388
  return {
290
389
  type: 'mutation:media',
@@ -296,8 +395,8 @@ var ViewportObserver = /*#__PURE__*/function () {
296
395
  };
297
396
  }
298
397
  if (fg('platform_ufo_exclude_3p_attribute_changes')) {
299
- var _checkWithinComponent = checkWithinComponent(target, 'UFOThirdPartySegment', _this.mapIs3pResult),
300
- isWithinThirdPartySegment = _checkWithinComponent.isWithin;
398
+ var _checkWithinComponent2 = checkWithinComponent(target, 'UFOThirdPartySegment', _this.mapIs3pResult),
399
+ isWithinThirdPartySegment = _checkWithinComponent2.isWithin;
301
400
  if (isWithinThirdPartySegment) {
302
401
  return {
303
402
  type: 'mutation:third-party-attribute',
@@ -370,9 +469,9 @@ var ViewportObserver = /*#__PURE__*/function () {
370
469
  };
371
470
  });
372
471
  });
373
- _defineProperty(this, "handleLayoutShift", function (_ref9) {
374
- var time = _ref9.time,
375
- changedRects = _ref9.changedRects;
472
+ _defineProperty(this, "handleLayoutShift", function (_ref0) {
473
+ var time = _ref0.time,
474
+ changedRects = _ref0.changedRects;
376
475
  var _iterator3 = _createForOfIteratorHelper(changedRects),
377
476
  _step3;
378
477
  try {
@@ -451,12 +550,12 @@ var ViewportObserver = /*#__PURE__*/function () {
451
550
  }, {
452
551
  key: "stop",
453
552
  value: function stop() {
454
- var _this$mutationObserve2, _this$intersectionObs1, _this$performanceObse2;
553
+ var _this$mutationObserve2, _this$intersectionObs10, _this$performanceObse2;
455
554
  if (!this.isStarted) {
456
555
  return;
457
556
  }
458
557
  (_this$mutationObserve2 = this.mutationObserver) === null || _this$mutationObserve2 === void 0 || _this$mutationObserve2.disconnect();
459
- (_this$intersectionObs1 = this.intersectionObserver) === null || _this$intersectionObs1 === void 0 || _this$intersectionObs1.disconnect();
558
+ (_this$intersectionObs10 = this.intersectionObserver) === null || _this$intersectionObs10 === void 0 || _this$intersectionObs10.disconnect();
460
559
  (_this$performanceObse2 = this.performanceObserver) === null || _this$performanceObse2 === void 0 || _this$performanceObse2.disconnect();
461
560
  this.isStarted = false;
462
561
  // Clean up caches when stopping
@@ -1,3 +1,8 @@
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
+ import { fg } from '@atlaskit/platform-feature-flags';
5
+ import { isZeroDimensionRectangle } from '../utils/is-zero-dimension-rectangle';
1
6
  function isValidEntry(entry) {
2
7
  return entry.isIntersecting && entry.intersectionRect.width > 0 && entry.intersectionRect.height > 0;
3
8
  }
@@ -12,12 +17,50 @@ export function createIntersectionObserver(_ref) {
12
17
  var validEntries = [];
13
18
  var startTime = performance.now();
14
19
  entries.forEach(function (entry) {
15
- if (!(entry.target instanceof HTMLElement) || !isValidEntry(entry)) {
20
+ if (!(entry.target instanceof HTMLElement)) {
21
+ return;
22
+ }
23
+ var tagOrCallback = callbacksPerElement.get(entry.target);
24
+ if (fg('platform_ufo_detect_zero_dimension_rectangles')) {
25
+ if (isZeroDimensionRectangle(entry.intersectionRect)) {
26
+ var zeroDimensionRectangleTagCallback = function zeroDimensionRectangleTagCallback(props) {
27
+ var tagOrCallbackResult = typeof tagOrCallback === 'function' ? tagOrCallback(props) : tagOrCallback;
28
+
29
+ // override as display-contents mutation
30
+ if (tagOrCallbackResult === 'mutation:element') {
31
+ return 'mutation:display-contents-children-element';
32
+ }
33
+
34
+ // override as display-contents mutation
35
+ if (tagOrCallbackResult && typeof tagOrCallbackResult !== 'string' && tagOrCallbackResult.type === 'mutation:attribute') {
36
+ return {
37
+ type: 'mutation:display-contents-children-attribute',
38
+ mutationData: tagOrCallbackResult.mutationData
39
+ };
40
+ }
41
+ return tagOrCallbackResult;
42
+ };
43
+ var _iterator = _createForOfIteratorHelper(entry.target.children),
44
+ _step;
45
+ try {
46
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
47
+ var child = _step.value;
48
+ observer.observe(child);
49
+ callbacksPerElement.set(child, zeroDimensionRectangleTagCallback);
50
+ }
51
+ } catch (err) {
52
+ _iterator.e(err);
53
+ } finally {
54
+ _iterator.f();
55
+ }
56
+ return;
57
+ }
58
+ }
59
+ if (!isValidEntry(entry)) {
16
60
  return;
17
61
  }
18
62
  var mutationTag = null;
19
63
  var mutationData = null;
20
- var tagOrCallback = callbacksPerElement.get(entry.target);
21
64
  if (typeof tagOrCallback === 'function') {
22
65
  var tagOrCallbackResult = tagOrCallback({
23
66
  target: entry.target,