@alfalab/core-components-select 15.0.0 → 15.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/Component.mobile.js +1 -1
  2. package/Component.modal.mobile.js +1 -1
  3. package/Component.responsive.js +1 -1
  4. package/components/arrow/Component.js +1 -1
  5. package/components/arrow/index.css +3 -3
  6. package/components/base-checkmark/Component.js +1 -1
  7. package/components/base-checkmark/index.css +4 -4
  8. package/components/base-option/Component.js +1 -1
  9. package/components/base-option/index.css +13 -13
  10. package/components/base-select/Component.js +1 -1
  11. package/components/base-select/index.css +8 -8
  12. package/components/base-select-mobile/Component.js +1 -1
  13. package/components/base-select-mobile/footer/Component.js +1 -1
  14. package/components/base-select-mobile/footer/index.css +5 -5
  15. package/components/base-select-mobile/index.css +11 -11
  16. package/components/checkmark/Component.js +1 -1
  17. package/components/checkmark/index.css +10 -10
  18. package/components/checkmark-mobile/Component.js +1 -1
  19. package/components/checkmark-mobile/index.css +6 -6
  20. package/components/field/Component.js +1 -1
  21. package/components/field/index.css +12 -12
  22. package/components/optgroup/Component.js +1 -1
  23. package/components/optgroup/index.css +6 -6
  24. package/components/option/Component.js +1 -1
  25. package/components/option/index.css +20 -20
  26. package/components/options-list/Component.js +1 -1
  27. package/components/options-list/index.css +9 -9
  28. package/components/virtual-options-list/Component.js +1 -1
  29. package/components/virtual-options-list/index.css +15 -15
  30. package/cssm/presets/index.js +1 -0
  31. package/cssm/presets/useLazyLoading/hook.js +1 -892
  32. package/cssm/shared.js +1 -0
  33. package/esm/Component.mobile.js +1 -1
  34. package/esm/Component.modal.mobile.js +1 -1
  35. package/esm/Component.responsive.js +1 -1
  36. package/esm/components/arrow/Component.js +1 -1
  37. package/esm/components/arrow/index.css +3 -3
  38. package/esm/components/base-checkmark/Component.js +1 -1
  39. package/esm/components/base-checkmark/index.css +4 -4
  40. package/esm/components/base-option/Component.js +1 -1
  41. package/esm/components/base-option/index.css +13 -13
  42. package/esm/components/base-select/Component.js +1 -1
  43. package/esm/components/base-select/index.css +8 -8
  44. package/esm/components/base-select-mobile/Component.js +1 -1
  45. package/esm/components/base-select-mobile/footer/Component.js +1 -1
  46. package/esm/components/base-select-mobile/footer/index.css +5 -5
  47. package/esm/components/base-select-mobile/index.css +11 -11
  48. package/esm/components/checkmark/Component.js +1 -1
  49. package/esm/components/checkmark/index.css +10 -10
  50. package/esm/components/checkmark-mobile/Component.js +1 -1
  51. package/esm/components/checkmark-mobile/index.css +6 -6
  52. package/esm/components/field/Component.js +1 -1
  53. package/esm/components/field/index.css +12 -12
  54. package/esm/components/optgroup/Component.js +1 -1
  55. package/esm/components/optgroup/index.css +6 -6
  56. package/esm/components/option/Component.js +1 -1
  57. package/esm/components/option/index.css +20 -20
  58. package/esm/components/options-list/Component.js +1 -1
  59. package/esm/components/options-list/index.css +9 -9
  60. package/esm/components/virtual-options-list/Component.js +1 -1
  61. package/esm/components/virtual-options-list/index.css +15 -15
  62. package/esm/index.js +1 -1
  63. package/esm/mobile.js +1 -1
  64. package/esm/presets/index.js +2 -1
  65. package/esm/presets/useLazyLoading/hook.js +1 -892
  66. package/esm/presets/useSelectWithApply/hook.js +1 -1
  67. package/esm/presets/useSelectWithApply/options-list-with-apply/Component.js +1 -1
  68. package/esm/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +1 -1
  69. package/esm/presets/useSelectWithApply/options-list-with-apply/footer/index.css +3 -3
  70. package/esm/presets/useSelectWithApply/options-list-with-apply/header/Component.js +1 -1
  71. package/esm/presets/useSelectWithApply/options-list-with-apply/header/index.css +3 -3
  72. package/esm/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -1
  73. package/esm/presets/useSelectWithApply/options-list-with-apply/index.js +1 -1
  74. package/esm/presets/useSelectWithLoading/hook.js +1 -1
  75. package/esm/presets/useSelectWithLoading/index.css +2 -2
  76. package/esm/shared.js +2 -1
  77. package/index.js +1 -1
  78. package/mobile.js +1 -1
  79. package/modern/Component.mobile.js +1 -1
  80. package/modern/Component.modal.mobile.js +1 -1
  81. package/modern/Component.responsive.js +1 -1
  82. package/modern/components/arrow/Component.js +1 -1
  83. package/modern/components/arrow/index.css +3 -3
  84. package/modern/components/base-checkmark/Component.js +1 -1
  85. package/modern/components/base-checkmark/index.css +4 -4
  86. package/modern/components/base-option/Component.js +1 -1
  87. package/modern/components/base-option/index.css +13 -13
  88. package/modern/components/base-select/Component.js +1 -1
  89. package/modern/components/base-select/index.css +8 -8
  90. package/modern/components/base-select-mobile/Component.js +1 -1
  91. package/modern/components/base-select-mobile/footer/Component.js +1 -1
  92. package/modern/components/base-select-mobile/footer/index.css +5 -5
  93. package/modern/components/base-select-mobile/index.css +11 -11
  94. package/modern/components/checkmark/Component.js +1 -1
  95. package/modern/components/checkmark/index.css +10 -10
  96. package/modern/components/checkmark-mobile/Component.js +1 -1
  97. package/modern/components/checkmark-mobile/index.css +6 -6
  98. package/modern/components/field/Component.js +1 -1
  99. package/modern/components/field/index.css +12 -12
  100. package/modern/components/optgroup/Component.js +1 -1
  101. package/modern/components/optgroup/index.css +6 -6
  102. package/modern/components/option/Component.js +1 -1
  103. package/modern/components/option/index.css +20 -20
  104. package/modern/components/options-list/Component.js +1 -1
  105. package/modern/components/options-list/index.css +9 -9
  106. package/modern/components/virtual-options-list/Component.js +1 -1
  107. package/modern/components/virtual-options-list/index.css +15 -15
  108. package/modern/index.js +1 -1
  109. package/modern/mobile.js +1 -1
  110. package/modern/presets/index.js +2 -1
  111. package/modern/presets/useLazyLoading/hook.js +1 -892
  112. package/modern/presets/useSelectWithApply/hook.js +1 -1
  113. package/modern/presets/useSelectWithApply/options-list-with-apply/Component.js +1 -1
  114. package/modern/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +1 -1
  115. package/modern/presets/useSelectWithApply/options-list-with-apply/footer/index.css +3 -3
  116. package/modern/presets/useSelectWithApply/options-list-with-apply/header/Component.js +1 -1
  117. package/modern/presets/useSelectWithApply/options-list-with-apply/header/index.css +3 -3
  118. package/modern/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -1
  119. package/modern/presets/useSelectWithApply/options-list-with-apply/index.js +1 -1
  120. package/modern/presets/useSelectWithLoading/hook.js +1 -1
  121. package/modern/presets/useSelectWithLoading/index.css +2 -2
  122. package/modern/shared.js +2 -1
  123. package/package.json +8 -7
  124. package/presets/index.js +2 -1
  125. package/presets/useLazyLoading/hook.js +1 -892
  126. package/presets/useSelectWithApply/hook.js +1 -1
  127. package/presets/useSelectWithApply/options-list-with-apply/Component.js +1 -1
  128. package/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +1 -1
  129. package/presets/useSelectWithApply/options-list-with-apply/footer/index.css +3 -3
  130. package/presets/useSelectWithApply/options-list-with-apply/header/Component.js +1 -1
  131. package/presets/useSelectWithApply/options-list-with-apply/header/index.css +3 -3
  132. package/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -1
  133. package/presets/useSelectWithApply/options-list-with-apply/index.js +1 -1
  134. package/presets/useSelectWithLoading/hook.js +1 -1
  135. package/presets/useSelectWithLoading/index.css +2 -2
  136. package/shared.js +2 -1
  137. /package/esm/{hook-326a5cea.d.ts → hook-cb30fc23.d.ts} +0 -0
  138. /package/esm/{hook-326a5cea.js → hook-cb30fc23.js} +0 -0
  139. /package/{hook-6e94be9c.d.ts → hook-3e654f56.d.ts} +0 -0
  140. /package/{hook-6e94be9c.js → hook-3e654f56.js} +0 -0
  141. /package/modern/{hook-e0fd0350.d.ts → hook-467b4d42.d.ts} +0 -0
  142. /package/modern/{hook-e0fd0350.js → hook-467b4d42.js} +0 -0
@@ -6,6 +6,7 @@ var tslib = require('tslib');
6
6
  var React = require('react');
7
7
  var coreComponentsSkeleton = require('@alfalab/core-components-skeleton');
8
8
  var components_option_Component = require('../../components/option/Component.js');
9
+ require('intersection-observer');
9
10
  require('classnames');
10
11
  require('../../components/checkmark/Component.js');
11
12
  require('@alfalab/core-components-badge');
@@ -18,898 +19,6 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
18
19
 
19
20
  var React__default = /*#__PURE__*/_interopDefaultCompat(React);
20
21
 
21
- /**
22
- * Copyright 2016 Google Inc. All Rights Reserved.
23
- *
24
- * Licensed under the W3C SOFTWARE AND DOCUMENT NOTICE AND LICENSE.
25
- *
26
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
27
- *
28
- */
29
- (function () {
30
- // Exit early if we're not running in a browser.
31
- if (typeof window !== 'object') {
32
- return;
33
- }
34
- // Exit early if all IntersectionObserver and IntersectionObserverEntry
35
- // features are natively supported.
36
- if ('IntersectionObserver' in window &&
37
- 'IntersectionObserverEntry' in window &&
38
- 'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
39
- // Minimal polyfill for Edge 15's lack of `isIntersecting`
40
- // See: https://github.com/w3c/IntersectionObserver/issues/211
41
- if (!('isIntersecting' in window.IntersectionObserverEntry.prototype)) {
42
- Object.defineProperty(window.IntersectionObserverEntry.prototype, 'isIntersecting', {
43
- get: function () {
44
- return this.intersectionRatio > 0;
45
- }
46
- });
47
- }
48
- return;
49
- }
50
- /**
51
- * Returns the embedding frame element, if any.
52
- * @param {!Document} doc
53
- * @return {!Element}
54
- */
55
- function getFrameElement(doc) {
56
- try {
57
- return doc.defaultView && doc.defaultView.frameElement || null;
58
- }
59
- catch (e) {
60
- // Ignore the error.
61
- return null;
62
- }
63
- }
64
- /**
65
- * A local reference to the root document.
66
- */
67
- var document = (function (startDoc) {
68
- var doc = startDoc;
69
- var frame = getFrameElement(doc);
70
- while (frame) {
71
- doc = frame.ownerDocument;
72
- frame = getFrameElement(doc);
73
- }
74
- return doc;
75
- })(window.document);
76
- /**
77
- * An IntersectionObserver registry. This registry exists to hold a strong
78
- * reference to IntersectionObserver instances currently observing a target
79
- * element. Without this registry, instances without another reference may be
80
- * garbage collected.
81
- */
82
- var registry = [];
83
- /**
84
- * The signal updater for cross-origin intersection. When not null, it means
85
- * that the polyfill is configured to work in a cross-origin mode.
86
- * @type {function(DOMRect|ClientRect, DOMRect|ClientRect)}
87
- */
88
- var crossOriginUpdater = null;
89
- /**
90
- * The current cross-origin intersection. Only used in the cross-origin mode.
91
- * @type {DOMRect|ClientRect}
92
- */
93
- var crossOriginRect = null;
94
- /**
95
- * Creates the global IntersectionObserverEntry constructor.
96
- * https://w3c.github.io/IntersectionObserver/#intersection-observer-entry
97
- * @param {Object} entry A dictionary of instance properties.
98
- * @constructor
99
- */
100
- function IntersectionObserverEntry(entry) {
101
- this.time = entry.time;
102
- this.target = entry.target;
103
- this.rootBounds = ensureDOMRect(entry.rootBounds);
104
- this.boundingClientRect = ensureDOMRect(entry.boundingClientRect);
105
- this.intersectionRect = ensureDOMRect(entry.intersectionRect || getEmptyRect());
106
- this.isIntersecting = !!entry.intersectionRect;
107
- // Calculates the intersection ratio.
108
- var targetRect = this.boundingClientRect;
109
- var targetArea = targetRect.width * targetRect.height;
110
- var intersectionRect = this.intersectionRect;
111
- var intersectionArea = intersectionRect.width * intersectionRect.height;
112
- // Sets intersection ratio.
113
- if (targetArea) {
114
- // Round the intersection ratio to avoid floating point math issues:
115
- // https://github.com/w3c/IntersectionObserver/issues/324
116
- this.intersectionRatio = Number((intersectionArea / targetArea).toFixed(4));
117
- }
118
- else {
119
- // If area is zero and is intersecting, sets to 1, otherwise to 0
120
- this.intersectionRatio = this.isIntersecting ? 1 : 0;
121
- }
122
- }
123
- /**
124
- * Creates the global IntersectionObserver constructor.
125
- * https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
126
- * @param {Function} callback The function to be invoked after intersection
127
- * changes have queued. The function is not invoked if the queue has
128
- * been emptied by calling the `takeRecords` method.
129
- * @param {Object=} opt_options Optional configuration options.
130
- * @constructor
131
- */
132
- function IntersectionObserver(callback, opt_options) {
133
- var options = opt_options || {};
134
- if (typeof callback != 'function') {
135
- throw new Error('callback must be a function');
136
- }
137
- if (options.root &&
138
- options.root.nodeType != 1 &&
139
- options.root.nodeType != 9) {
140
- throw new Error('root must be a Document or Element');
141
- }
142
- // Binds and throttles `this._checkForIntersections`.
143
- this._checkForIntersections = throttle(this._checkForIntersections.bind(this), this.THROTTLE_TIMEOUT);
144
- // Private properties.
145
- this._callback = callback;
146
- this._observationTargets = [];
147
- this._queuedEntries = [];
148
- this._rootMarginValues = this._parseRootMargin(options.rootMargin);
149
- // Public properties.
150
- this.thresholds = this._initThresholds(options.threshold);
151
- this.root = options.root || null;
152
- this.rootMargin = this._rootMarginValues.map(function (margin) {
153
- return margin.value + margin.unit;
154
- }).join(' ');
155
- /** @private @const {!Array<!Document>} */
156
- this._monitoringDocuments = [];
157
- /** @private @const {!Array<function()>} */
158
- this._monitoringUnsubscribes = [];
159
- }
160
- /**
161
- * The minimum interval within which the document will be checked for
162
- * intersection changes.
163
- */
164
- IntersectionObserver.prototype.THROTTLE_TIMEOUT = 100;
165
- /**
166
- * The frequency in which the polyfill polls for intersection changes.
167
- * this can be updated on a per instance basis and must be set prior to
168
- * calling `observe` on the first target.
169
- */
170
- IntersectionObserver.prototype.POLL_INTERVAL = null;
171
- /**
172
- * Use a mutation observer on the root element
173
- * to detect intersection changes.
174
- */
175
- IntersectionObserver.prototype.USE_MUTATION_OBSERVER = true;
176
- /**
177
- * Sets up the polyfill in the cross-origin mode. The result is the
178
- * updater function that accepts two arguments: `boundingClientRect` and
179
- * `intersectionRect` - just as these fields would be available to the
180
- * parent via `IntersectionObserverEntry`. This function should be called
181
- * each time the iframe receives intersection information from the parent
182
- * window, e.g. via messaging.
183
- * @return {function(DOMRect|ClientRect, DOMRect|ClientRect)}
184
- */
185
- IntersectionObserver._setupCrossOriginUpdater = function () {
186
- if (!crossOriginUpdater) {
187
- /**
188
- * @param {DOMRect|ClientRect} boundingClientRect
189
- * @param {DOMRect|ClientRect} intersectionRect
190
- */
191
- crossOriginUpdater = function (boundingClientRect, intersectionRect) {
192
- if (!boundingClientRect || !intersectionRect) {
193
- crossOriginRect = getEmptyRect();
194
- }
195
- else {
196
- crossOriginRect = convertFromParentRect(boundingClientRect, intersectionRect);
197
- }
198
- registry.forEach(function (observer) {
199
- observer._checkForIntersections();
200
- });
201
- };
202
- }
203
- return crossOriginUpdater;
204
- };
205
- /**
206
- * Resets the cross-origin mode.
207
- */
208
- IntersectionObserver._resetCrossOriginUpdater = function () {
209
- crossOriginUpdater = null;
210
- crossOriginRect = null;
211
- };
212
- /**
213
- * Starts observing a target element for intersection changes based on
214
- * the thresholds values.
215
- * @param {Element} target The DOM element to observe.
216
- */
217
- IntersectionObserver.prototype.observe = function (target) {
218
- var isTargetAlreadyObserved = this._observationTargets.some(function (item) {
219
- return item.element == target;
220
- });
221
- if (isTargetAlreadyObserved) {
222
- return;
223
- }
224
- if (!(target && target.nodeType == 1)) {
225
- throw new Error('target must be an Element');
226
- }
227
- this._registerInstance();
228
- this._observationTargets.push({ element: target, entry: null });
229
- this._monitorIntersections(target.ownerDocument);
230
- this._checkForIntersections();
231
- };
232
- /**
233
- * Stops observing a target element for intersection changes.
234
- * @param {Element} target The DOM element to observe.
235
- */
236
- IntersectionObserver.prototype.unobserve = function (target) {
237
- this._observationTargets =
238
- this._observationTargets.filter(function (item) {
239
- return item.element != target;
240
- });
241
- this._unmonitorIntersections(target.ownerDocument);
242
- if (this._observationTargets.length == 0) {
243
- this._unregisterInstance();
244
- }
245
- };
246
- /**
247
- * Stops observing all target elements for intersection changes.
248
- */
249
- IntersectionObserver.prototype.disconnect = function () {
250
- this._observationTargets = [];
251
- this._unmonitorAllIntersections();
252
- this._unregisterInstance();
253
- };
254
- /**
255
- * Returns any queue entries that have not yet been reported to the
256
- * callback and clears the queue. This can be used in conjunction with the
257
- * callback to obtain the absolute most up-to-date intersection information.
258
- * @return {Array} The currently queued entries.
259
- */
260
- IntersectionObserver.prototype.takeRecords = function () {
261
- var records = this._queuedEntries.slice();
262
- this._queuedEntries = [];
263
- return records;
264
- };
265
- /**
266
- * Accepts the threshold value from the user configuration object and
267
- * returns a sorted array of unique threshold values. If a value is not
268
- * between 0 and 1 and error is thrown.
269
- * @private
270
- * @param {Array|number=} opt_threshold An optional threshold value or
271
- * a list of threshold values, defaulting to [0].
272
- * @return {Array} A sorted list of unique and valid threshold values.
273
- */
274
- IntersectionObserver.prototype._initThresholds = function (opt_threshold) {
275
- var threshold = opt_threshold || [0];
276
- if (!Array.isArray(threshold))
277
- threshold = [threshold];
278
- return threshold.sort().filter(function (t, i, a) {
279
- if (typeof t != 'number' || isNaN(t) || t < 0 || t > 1) {
280
- throw new Error('threshold must be a number between 0 and 1 inclusively');
281
- }
282
- return t !== a[i - 1];
283
- });
284
- };
285
- /**
286
- * Accepts the rootMargin value from the user configuration object
287
- * and returns an array of the four margin values as an object containing
288
- * the value and unit properties. If any of the values are not properly
289
- * formatted or use a unit other than px or %, and error is thrown.
290
- * @private
291
- * @param {string=} opt_rootMargin An optional rootMargin value,
292
- * defaulting to '0px'.
293
- * @return {Array<Object>} An array of margin objects with the keys
294
- * value and unit.
295
- */
296
- IntersectionObserver.prototype._parseRootMargin = function (opt_rootMargin) {
297
- var marginString = opt_rootMargin || '0px';
298
- var margins = marginString.split(/\s+/).map(function (margin) {
299
- var parts = /^(-?\d*\.?\d+)(px|%)$/.exec(margin);
300
- if (!parts) {
301
- throw new Error('rootMargin must be specified in pixels or percent');
302
- }
303
- return { value: parseFloat(parts[1]), unit: parts[2] };
304
- });
305
- // Handles shorthand.
306
- margins[1] = margins[1] || margins[0];
307
- margins[2] = margins[2] || margins[0];
308
- margins[3] = margins[3] || margins[1];
309
- return margins;
310
- };
311
- /**
312
- * Starts polling for intersection changes if the polling is not already
313
- * happening, and if the page's visibility state is visible.
314
- * @param {!Document} doc
315
- * @private
316
- */
317
- IntersectionObserver.prototype._monitorIntersections = function (doc) {
318
- var win = doc.defaultView;
319
- if (!win) {
320
- // Already destroyed.
321
- return;
322
- }
323
- if (this._monitoringDocuments.indexOf(doc) != -1) {
324
- // Already monitoring.
325
- return;
326
- }
327
- // Private state for monitoring.
328
- var callback = this._checkForIntersections;
329
- var monitoringInterval = null;
330
- var domObserver = null;
331
- // If a poll interval is set, use polling instead of listening to
332
- // resize and scroll events or DOM mutations.
333
- if (this.POLL_INTERVAL) {
334
- monitoringInterval = win.setInterval(callback, this.POLL_INTERVAL);
335
- }
336
- else {
337
- addEvent(win, 'resize', callback, true);
338
- addEvent(doc, 'scroll', callback, true);
339
- if (this.USE_MUTATION_OBSERVER && 'MutationObserver' in win) {
340
- domObserver = new win.MutationObserver(callback);
341
- domObserver.observe(doc, {
342
- attributes: true,
343
- childList: true,
344
- characterData: true,
345
- subtree: true
346
- });
347
- }
348
- }
349
- this._monitoringDocuments.push(doc);
350
- this._monitoringUnsubscribes.push(function () {
351
- // Get the window object again. When a friendly iframe is destroyed, it
352
- // will be null.
353
- var win = doc.defaultView;
354
- if (win) {
355
- if (monitoringInterval) {
356
- win.clearInterval(monitoringInterval);
357
- }
358
- removeEvent(win, 'resize', callback, true);
359
- }
360
- removeEvent(doc, 'scroll', callback, true);
361
- if (domObserver) {
362
- domObserver.disconnect();
363
- }
364
- });
365
- // Also monitor the parent.
366
- var rootDoc = (this.root && (this.root.ownerDocument || this.root)) || document;
367
- if (doc != rootDoc) {
368
- var frame = getFrameElement(doc);
369
- if (frame) {
370
- this._monitorIntersections(frame.ownerDocument);
371
- }
372
- }
373
- };
374
- /**
375
- * Stops polling for intersection changes.
376
- * @param {!Document} doc
377
- * @private
378
- */
379
- IntersectionObserver.prototype._unmonitorIntersections = function (doc) {
380
- var index = this._monitoringDocuments.indexOf(doc);
381
- if (index == -1) {
382
- return;
383
- }
384
- var rootDoc = (this.root && (this.root.ownerDocument || this.root)) || document;
385
- // Check if any dependent targets are still remaining.
386
- var hasDependentTargets = this._observationTargets.some(function (item) {
387
- var itemDoc = item.element.ownerDocument;
388
- // Target is in this context.
389
- if (itemDoc == doc) {
390
- return true;
391
- }
392
- // Target is nested in this context.
393
- while (itemDoc && itemDoc != rootDoc) {
394
- var frame = getFrameElement(itemDoc);
395
- itemDoc = frame && frame.ownerDocument;
396
- if (itemDoc == doc) {
397
- return true;
398
- }
399
- }
400
- return false;
401
- });
402
- if (hasDependentTargets) {
403
- return;
404
- }
405
- // Unsubscribe.
406
- var unsubscribe = this._monitoringUnsubscribes[index];
407
- this._monitoringDocuments.splice(index, 1);
408
- this._monitoringUnsubscribes.splice(index, 1);
409
- unsubscribe();
410
- // Also unmonitor the parent.
411
- if (doc != rootDoc) {
412
- var frame = getFrameElement(doc);
413
- if (frame) {
414
- this._unmonitorIntersections(frame.ownerDocument);
415
- }
416
- }
417
- };
418
- /**
419
- * Stops polling for intersection changes.
420
- * @param {!Document} doc
421
- * @private
422
- */
423
- IntersectionObserver.prototype._unmonitorAllIntersections = function () {
424
- var unsubscribes = this._monitoringUnsubscribes.slice(0);
425
- this._monitoringDocuments.length = 0;
426
- this._monitoringUnsubscribes.length = 0;
427
- for (var i = 0; i < unsubscribes.length; i++) {
428
- unsubscribes[i]();
429
- }
430
- };
431
- /**
432
- * Scans each observation target for intersection changes and adds them
433
- * to the internal entries queue. If new entries are found, it
434
- * schedules the callback to be invoked.
435
- * @private
436
- */
437
- IntersectionObserver.prototype._checkForIntersections = function () {
438
- if (!this.root && crossOriginUpdater && !crossOriginRect) {
439
- // Cross origin monitoring, but no initial data available yet.
440
- return;
441
- }
442
- var rootIsInDom = this._rootIsInDom();
443
- var rootRect = rootIsInDom ? this._getRootRect() : getEmptyRect();
444
- this._observationTargets.forEach(function (item) {
445
- var target = item.element;
446
- var targetRect = getBoundingClientRect(target);
447
- var rootContainsTarget = this._rootContainsTarget(target);
448
- var oldEntry = item.entry;
449
- var intersectionRect = rootIsInDom && rootContainsTarget &&
450
- this._computeTargetAndRootIntersection(target, targetRect, rootRect);
451
- var rootBounds = null;
452
- if (!this._rootContainsTarget(target)) {
453
- rootBounds = getEmptyRect();
454
- }
455
- else if (!crossOriginUpdater || this.root) {
456
- rootBounds = rootRect;
457
- }
458
- var newEntry = item.entry = new IntersectionObserverEntry({
459
- time: now(),
460
- target: target,
461
- boundingClientRect: targetRect,
462
- rootBounds: rootBounds,
463
- intersectionRect: intersectionRect
464
- });
465
- if (!oldEntry) {
466
- this._queuedEntries.push(newEntry);
467
- }
468
- else if (rootIsInDom && rootContainsTarget) {
469
- // If the new entry intersection ratio has crossed any of the
470
- // thresholds, add a new entry.
471
- if (this._hasCrossedThreshold(oldEntry, newEntry)) {
472
- this._queuedEntries.push(newEntry);
473
- }
474
- }
475
- else {
476
- // If the root is not in the DOM or target is not contained within
477
- // root but the previous entry for this target had an intersection,
478
- // add a new record indicating removal.
479
- if (oldEntry && oldEntry.isIntersecting) {
480
- this._queuedEntries.push(newEntry);
481
- }
482
- }
483
- }, this);
484
- if (this._queuedEntries.length) {
485
- this._callback(this.takeRecords(), this);
486
- }
487
- };
488
- /**
489
- * Accepts a target and root rect computes the intersection between then
490
- * following the algorithm in the spec.
491
- * TODO(philipwalton): at this time clip-path is not considered.
492
- * https://w3c.github.io/IntersectionObserver/#calculate-intersection-rect-algo
493
- * @param {Element} target The target DOM element
494
- * @param {Object} targetRect The bounding rect of the target.
495
- * @param {Object} rootRect The bounding rect of the root after being
496
- * expanded by the rootMargin value.
497
- * @return {?Object} The final intersection rect object or undefined if no
498
- * intersection is found.
499
- * @private
500
- */
501
- IntersectionObserver.prototype._computeTargetAndRootIntersection =
502
- function (target, targetRect, rootRect) {
503
- // If the element isn't displayed, an intersection can't happen.
504
- if (window.getComputedStyle(target).display == 'none')
505
- return;
506
- var intersectionRect = targetRect;
507
- var parent = getParentNode(target);
508
- var atRoot = false;
509
- while (!atRoot && parent) {
510
- var parentRect = null;
511
- var parentComputedStyle = parent.nodeType == 1 ?
512
- window.getComputedStyle(parent) : {};
513
- // If the parent isn't displayed, an intersection can't happen.
514
- if (parentComputedStyle.display == 'none')
515
- return null;
516
- if (parent == this.root || parent.nodeType == /* DOCUMENT */ 9) {
517
- atRoot = true;
518
- if (parent == this.root || parent == document) {
519
- if (crossOriginUpdater && !this.root) {
520
- if (!crossOriginRect ||
521
- crossOriginRect.width == 0 && crossOriginRect.height == 0) {
522
- // A 0-size cross-origin intersection means no-intersection.
523
- parent = null;
524
- parentRect = null;
525
- intersectionRect = null;
526
- }
527
- else {
528
- parentRect = crossOriginRect;
529
- }
530
- }
531
- else {
532
- parentRect = rootRect;
533
- }
534
- }
535
- else {
536
- // Check if there's a frame that can be navigated to.
537
- var frame = getParentNode(parent);
538
- var frameRect = frame && getBoundingClientRect(frame);
539
- var frameIntersect = frame &&
540
- this._computeTargetAndRootIntersection(frame, frameRect, rootRect);
541
- if (frameRect && frameIntersect) {
542
- parent = frame;
543
- parentRect = convertFromParentRect(frameRect, frameIntersect);
544
- }
545
- else {
546
- parent = null;
547
- intersectionRect = null;
548
- }
549
- }
550
- }
551
- else {
552
- // If the element has a non-visible overflow, and it's not the <body>
553
- // or <html> element, update the intersection rect.
554
- // Note: <body> and <html> cannot be clipped to a rect that's not also
555
- // the document rect, so no need to compute a new intersection.
556
- var doc = parent.ownerDocument;
557
- if (parent != doc.body &&
558
- parent != doc.documentElement &&
559
- parentComputedStyle.overflow != 'visible') {
560
- parentRect = getBoundingClientRect(parent);
561
- }
562
- }
563
- // If either of the above conditionals set a new parentRect,
564
- // calculate new intersection data.
565
- if (parentRect) {
566
- intersectionRect = computeRectIntersection(parentRect, intersectionRect);
567
- }
568
- if (!intersectionRect)
569
- break;
570
- parent = parent && getParentNode(parent);
571
- }
572
- return intersectionRect;
573
- };
574
- /**
575
- * Returns the root rect after being expanded by the rootMargin value.
576
- * @return {ClientRect} The expanded root rect.
577
- * @private
578
- */
579
- IntersectionObserver.prototype._getRootRect = function () {
580
- var rootRect;
581
- if (this.root && !isDoc(this.root)) {
582
- rootRect = getBoundingClientRect(this.root);
583
- }
584
- else {
585
- // Use <html>/<body> instead of window since scroll bars affect size.
586
- var doc = isDoc(this.root) ? this.root : document;
587
- var html = doc.documentElement;
588
- var body = doc.body;
589
- rootRect = {
590
- top: 0,
591
- left: 0,
592
- right: html.clientWidth || body.clientWidth,
593
- width: html.clientWidth || body.clientWidth,
594
- bottom: html.clientHeight || body.clientHeight,
595
- height: html.clientHeight || body.clientHeight
596
- };
597
- }
598
- return this._expandRectByRootMargin(rootRect);
599
- };
600
- /**
601
- * Accepts a rect and expands it by the rootMargin value.
602
- * @param {DOMRect|ClientRect} rect The rect object to expand.
603
- * @return {ClientRect} The expanded rect.
604
- * @private
605
- */
606
- IntersectionObserver.prototype._expandRectByRootMargin = function (rect) {
607
- var margins = this._rootMarginValues.map(function (margin, i) {
608
- return margin.unit == 'px' ? margin.value :
609
- margin.value * (i % 2 ? rect.width : rect.height) / 100;
610
- });
611
- var newRect = {
612
- top: rect.top - margins[0],
613
- right: rect.right + margins[1],
614
- bottom: rect.bottom + margins[2],
615
- left: rect.left - margins[3]
616
- };
617
- newRect.width = newRect.right - newRect.left;
618
- newRect.height = newRect.bottom - newRect.top;
619
- return newRect;
620
- };
621
- /**
622
- * Accepts an old and new entry and returns true if at least one of the
623
- * threshold values has been crossed.
624
- * @param {?IntersectionObserverEntry} oldEntry The previous entry for a
625
- * particular target element or null if no previous entry exists.
626
- * @param {IntersectionObserverEntry} newEntry The current entry for a
627
- * particular target element.
628
- * @return {boolean} Returns true if a any threshold has been crossed.
629
- * @private
630
- */
631
- IntersectionObserver.prototype._hasCrossedThreshold =
632
- function (oldEntry, newEntry) {
633
- // To make comparing easier, an entry that has a ratio of 0
634
- // but does not actually intersect is given a value of -1
635
- var oldRatio = oldEntry && oldEntry.isIntersecting ?
636
- oldEntry.intersectionRatio || 0 : -1;
637
- var newRatio = newEntry.isIntersecting ?
638
- newEntry.intersectionRatio || 0 : -1;
639
- // Ignore unchanged ratios
640
- if (oldRatio === newRatio)
641
- return;
642
- for (var i = 0; i < this.thresholds.length; i++) {
643
- var threshold = this.thresholds[i];
644
- // Return true if an entry matches a threshold or if the new ratio
645
- // and the old ratio are on the opposite sides of a threshold.
646
- if (threshold == oldRatio || threshold == newRatio ||
647
- threshold < oldRatio !== threshold < newRatio) {
648
- return true;
649
- }
650
- }
651
- };
652
- /**
653
- * Returns whether or not the root element is an element and is in the DOM.
654
- * @return {boolean} True if the root element is an element and is in the DOM.
655
- * @private
656
- */
657
- IntersectionObserver.prototype._rootIsInDom = function () {
658
- return !this.root || containsDeep(document, this.root);
659
- };
660
- /**
661
- * Returns whether or not the target element is a child of root.
662
- * @param {Element} target The target element to check.
663
- * @return {boolean} True if the target element is a child of root.
664
- * @private
665
- */
666
- IntersectionObserver.prototype._rootContainsTarget = function (target) {
667
- var rootDoc = (this.root && (this.root.ownerDocument || this.root)) || document;
668
- return (containsDeep(rootDoc, target) &&
669
- (!this.root || rootDoc == target.ownerDocument));
670
- };
671
- /**
672
- * Adds the instance to the global IntersectionObserver registry if it isn't
673
- * already present.
674
- * @private
675
- */
676
- IntersectionObserver.prototype._registerInstance = function () {
677
- if (registry.indexOf(this) < 0) {
678
- registry.push(this);
679
- }
680
- };
681
- /**
682
- * Removes the instance from the global IntersectionObserver registry.
683
- * @private
684
- */
685
- IntersectionObserver.prototype._unregisterInstance = function () {
686
- var index = registry.indexOf(this);
687
- if (index != -1)
688
- registry.splice(index, 1);
689
- };
690
- /**
691
- * Returns the result of the performance.now() method or null in browsers
692
- * that don't support the API.
693
- * @return {number} The elapsed time since the page was requested.
694
- */
695
- function now() {
696
- return window.performance && performance.now && performance.now();
697
- }
698
- /**
699
- * Throttles a function and delays its execution, so it's only called at most
700
- * once within a given time period.
701
- * @param {Function} fn The function to throttle.
702
- * @param {number} timeout The amount of time that must pass before the
703
- * function can be called again.
704
- * @return {Function} The throttled function.
705
- */
706
- function throttle(fn, timeout) {
707
- var timer = null;
708
- return function () {
709
- if (!timer) {
710
- timer = setTimeout(function () {
711
- fn();
712
- timer = null;
713
- }, timeout);
714
- }
715
- };
716
- }
717
- /**
718
- * Adds an event handler to a DOM node ensuring cross-browser compatibility.
719
- * @param {Node} node The DOM node to add the event handler to.
720
- * @param {string} event The event name.
721
- * @param {Function} fn The event handler to add.
722
- * @param {boolean} opt_useCapture Optionally adds the even to the capture
723
- * phase. Note: this only works in modern browsers.
724
- */
725
- function addEvent(node, event, fn, opt_useCapture) {
726
- if (typeof node.addEventListener == 'function') {
727
- node.addEventListener(event, fn, opt_useCapture || false);
728
- }
729
- else if (typeof node.attachEvent == 'function') {
730
- node.attachEvent('on' + event, fn);
731
- }
732
- }
733
- /**
734
- * Removes a previously added event handler from a DOM node.
735
- * @param {Node} node The DOM node to remove the event handler from.
736
- * @param {string} event The event name.
737
- * @param {Function} fn The event handler to remove.
738
- * @param {boolean} opt_useCapture If the event handler was added with this
739
- * flag set to true, it should be set to true here in order to remove it.
740
- */
741
- function removeEvent(node, event, fn, opt_useCapture) {
742
- if (typeof node.removeEventListener == 'function') {
743
- node.removeEventListener(event, fn, opt_useCapture || false);
744
- }
745
- else if (typeof node.detatchEvent == 'function') {
746
- node.detatchEvent('on' + event, fn);
747
- }
748
- }
749
- /**
750
- * Returns the intersection between two rect objects.
751
- * @param {Object} rect1 The first rect.
752
- * @param {Object} rect2 The second rect.
753
- * @return {?Object|?ClientRect} The intersection rect or undefined if no
754
- * intersection is found.
755
- */
756
- function computeRectIntersection(rect1, rect2) {
757
- var top = Math.max(rect1.top, rect2.top);
758
- var bottom = Math.min(rect1.bottom, rect2.bottom);
759
- var left = Math.max(rect1.left, rect2.left);
760
- var right = Math.min(rect1.right, rect2.right);
761
- var width = right - left;
762
- var height = bottom - top;
763
- return (width >= 0 && height >= 0) && {
764
- top: top,
765
- bottom: bottom,
766
- left: left,
767
- right: right,
768
- width: width,
769
- height: height
770
- } || null;
771
- }
772
- /**
773
- * Shims the native getBoundingClientRect for compatibility with older IE.
774
- * @param {Element} el The element whose bounding rect to get.
775
- * @return {DOMRect|ClientRect} The (possibly shimmed) rect of the element.
776
- */
777
- function getBoundingClientRect(el) {
778
- var rect;
779
- try {
780
- rect = el.getBoundingClientRect();
781
- }
782
- catch (err) {
783
- // Ignore Windows 7 IE11 "Unspecified error"
784
- // https://github.com/w3c/IntersectionObserver/pull/205
785
- }
786
- if (!rect)
787
- return getEmptyRect();
788
- // Older IE
789
- if (!(rect.width && rect.height)) {
790
- rect = {
791
- top: rect.top,
792
- right: rect.right,
793
- bottom: rect.bottom,
794
- left: rect.left,
795
- width: rect.right - rect.left,
796
- height: rect.bottom - rect.top
797
- };
798
- }
799
- return rect;
800
- }
801
- /**
802
- * Returns an empty rect object. An empty rect is returned when an element
803
- * is not in the DOM.
804
- * @return {ClientRect} The empty rect.
805
- */
806
- function getEmptyRect() {
807
- return {
808
- top: 0,
809
- bottom: 0,
810
- left: 0,
811
- right: 0,
812
- width: 0,
813
- height: 0
814
- };
815
- }
816
- /**
817
- * Ensure that the result has all of the necessary fields of the DOMRect.
818
- * Specifically this ensures that `x` and `y` fields are set.
819
- *
820
- * @param {?DOMRect|?ClientRect} rect
821
- * @return {?DOMRect}
822
- */
823
- function ensureDOMRect(rect) {
824
- // A `DOMRect` object has `x` and `y` fields.
825
- if (!rect || 'x' in rect) {
826
- return rect;
827
- }
828
- // A IE's `ClientRect` type does not have `x` and `y`. The same is the case
829
- // for internally calculated Rect objects. For the purposes of
830
- // `IntersectionObserver`, it's sufficient to simply mirror `left` and `top`
831
- // for these fields.
832
- return {
833
- top: rect.top,
834
- y: rect.top,
835
- bottom: rect.bottom,
836
- left: rect.left,
837
- x: rect.left,
838
- right: rect.right,
839
- width: rect.width,
840
- height: rect.height
841
- };
842
- }
843
- /**
844
- * Inverts the intersection and bounding rect from the parent (frame) BCR to
845
- * the local BCR space.
846
- * @param {DOMRect|ClientRect} parentBoundingRect The parent's bound client rect.
847
- * @param {DOMRect|ClientRect} parentIntersectionRect The parent's own intersection rect.
848
- * @return {ClientRect} The local root bounding rect for the parent's children.
849
- */
850
- function convertFromParentRect(parentBoundingRect, parentIntersectionRect) {
851
- var top = parentIntersectionRect.top - parentBoundingRect.top;
852
- var left = parentIntersectionRect.left - parentBoundingRect.left;
853
- return {
854
- top: top,
855
- left: left,
856
- height: parentIntersectionRect.height,
857
- width: parentIntersectionRect.width,
858
- bottom: top + parentIntersectionRect.height,
859
- right: left + parentIntersectionRect.width
860
- };
861
- }
862
- /**
863
- * Checks to see if a parent element contains a child element (including inside
864
- * shadow DOM).
865
- * @param {Node} parent The parent element.
866
- * @param {Node} child The child element.
867
- * @return {boolean} True if the parent node contains the child node.
868
- */
869
- function containsDeep(parent, child) {
870
- var node = child;
871
- while (node) {
872
- if (node == parent)
873
- return true;
874
- node = getParentNode(node);
875
- }
876
- return false;
877
- }
878
- /**
879
- * Gets the parent node of an element or its host element if the parent node
880
- * is a shadow root.
881
- * @param {Node} node The node whose parent to get.
882
- * @return {Node|null} The parent node or null if no parent exists.
883
- */
884
- function getParentNode(node) {
885
- var parent = node.parentNode;
886
- if (node.nodeType == /* DOCUMENT */ 9 && node != document) {
887
- // If this node is a document node, look for the embedding frame.
888
- return getFrameElement(node);
889
- }
890
- // If the parent has element that is assigned through shadow root slot
891
- if (parent && parent.assignedSlot) {
892
- parent = parent.assignedSlot.parentNode;
893
- }
894
- if (parent && parent.nodeType == 11 && parent.host) {
895
- // If the parent is a shadow root, return the host element.
896
- return parent.host;
897
- }
898
- return parent;
899
- }
900
- /**
901
- * Returns true if `node` is a Document.
902
- * @param {!Node} node
903
- * @returns {boolean}
904
- */
905
- function isDoc(node) {
906
- return node && node.nodeType === 9;
907
- }
908
- // Exposes the constructors globally.
909
- window.IntersectionObserver = IntersectionObserver;
910
- window.IntersectionObserverEntry = IntersectionObserverEntry;
911
- }());
912
-
913
22
  var DEBOUNCE_TIMEOUT = 300;
914
23
  var actions = {
915
24
  fetchOptionsStart: function () {