@hi-ui/table 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 +40 -0
- package/lib/cjs/BaseTable.js +136 -189
- package/lib/cjs/ColGroupContent.js +5 -28
- package/lib/cjs/SettingDrawer.js +76 -127
- package/lib/cjs/Table.js +107 -171
- package/lib/cjs/TableAdvancedFilter.js +49 -85
- package/lib/cjs/TableBody.js +33 -69
- package/lib/cjs/TableCell.js +56 -102
- package/lib/cjs/TableColumnMenu.js +39 -77
- package/lib/cjs/TableEmbedRow.js +11 -38
- package/lib/cjs/TableHeader.js +8 -33
- package/lib/cjs/TableRow.js +48 -88
- package/lib/cjs/TableSettingMenu.js +48 -94
- package/lib/cjs/TbodyContent.js +28 -56
- package/lib/cjs/TheadContent.js +20 -49
- package/lib/cjs/_virtual/index.js +0 -3
- package/lib/cjs/_virtual/index2.js +0 -3
- package/lib/cjs/_virtual/react-is.development.js +0 -3
- package/lib/cjs/_virtual/react-is.production.min.js +0 -3
- package/lib/cjs/context.js +0 -9
- package/lib/cjs/hooks/use-async-switch.js +13 -51
- package/lib/cjs/hooks/use-check.js +47 -77
- package/lib/cjs/hooks/use-col-hidden.js +16 -28
- package/lib/cjs/hooks/use-col-set.js +5 -18
- package/lib/cjs/hooks/use-col-sorter.js +18 -32
- package/lib/cjs/hooks/use-col-width.js +21 -57
- package/lib/cjs/hooks/use-colgroup.js +63 -85
- package/lib/cjs/hooks/use-drag.js +10 -31
- package/lib/cjs/hooks/use-embed-expand.js +23 -68
- package/lib/cjs/hooks/use-expand.js +32 -64
- package/lib/cjs/hooks/use-pagination.js +19 -50
- package/lib/cjs/hooks/use-queue.js +2 -14
- package/lib/cjs/icons/index.js +4 -21
- package/lib/cjs/index.js +0 -4
- package/lib/cjs/node_modules/classnames/index.js +2 -11
- package/lib/cjs/node_modules/perfect-scrollbar/dist/perfect-scrollbar.esm.js +31 -227
- package/lib/cjs/node_modules/rc-resize-observer/es/index.js +10 -68
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/Children/toArray.js +1 -17
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/Dom/findDOMNode.js +1 -14
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/ref.js +1 -25
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/warning.js +1 -5
- package/lib/cjs/node_modules/rc-util/es/Dom/canUseDom.js +0 -2
- package/lib/cjs/node_modules/rc-util/es/Dom/findDOMNode.js +1 -14
- package/lib/cjs/node_modules/rc-util/es/hooks/useLayoutEffect.js +2 -9
- package/lib/cjs/node_modules/rc-util/es/raf.js +0 -11
- package/lib/cjs/node_modules/rc-virtual-list/es/Filler.js +6 -25
- package/lib/cjs/node_modules/rc-virtual-list/es/Item.js +3 -14
- package/lib/cjs/node_modules/rc-virtual-list/es/List.js +103 -194
- package/lib/cjs/node_modules/rc-virtual-list/es/ScrollBar.js +16 -96
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useChildren.js +2 -11
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useDiffItem.js +8 -34
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js +0 -10
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useHeights.js +6 -39
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js +0 -16
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useOriginScroll.js +4 -9
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useScrollTo.js +3 -28
- package/lib/cjs/node_modules/rc-virtual-list/es/index.js +0 -2
- package/lib/cjs/node_modules/rc-virtual-list/es/utils/CacheMap.js +2 -9
- package/lib/cjs/node_modules/rc-virtual-list/es/utils/algorithmUtil.js +0 -15
- package/lib/cjs/node_modules/rc-virtual-list/es/utils/isFirefox.js +0 -2
- package/lib/cjs/node_modules/react-is/cjs/react-is.development.js +3 -29
- package/lib/cjs/node_modules/react-is/cjs/react-is.production.min.js +19 -45
- package/lib/cjs/node_modules/react-is/index.js +0 -5
- package/lib/cjs/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +83 -248
- package/lib/cjs/packages/hooks/use-merge-refs/lib/esm/index.js +3 -14
- package/lib/cjs/packages/ui/scrollbar/lib/esm/Scrollbar.js +48 -86
- package/lib/cjs/packages/ui/scrollbar/lib/esm/styles/index.scss.js +1 -15
- package/lib/cjs/packages/ui/scrollbar/lib/esm/utils/index.js +0 -13
- package/lib/cjs/styles/index.scss.js +1 -4
- package/lib/cjs/use-table.js +268 -355
- package/lib/cjs/utils/index.js +11 -45
- package/lib/esm/BaseTable.js +117 -138
- package/lib/esm/ColGroupContent.js +3 -9
- package/lib/esm/SettingDrawer.js +64 -83
- package/lib/esm/Table.js +97 -124
- package/lib/esm/TableAdvancedFilter.js +37 -47
- package/lib/esm/TableBody.js +24 -34
- package/lib/esm/TableCell.js +48 -72
- package/lib/esm/TableColumnMenu.js +24 -38
- package/lib/esm/TableEmbedRow.js +8 -15
- package/lib/esm/TableHeader.js +5 -11
- package/lib/esm/TableRow.js +36 -51
- package/lib/esm/TableSettingMenu.js +33 -49
- package/lib/esm/TbodyContent.js +20 -27
- package/lib/esm/TheadContent.js +14 -21
- package/lib/esm/context.js +0 -4
- package/lib/esm/hooks/use-async-switch.js +9 -28
- package/lib/esm/hooks/use-check.js +42 -55
- package/lib/esm/hooks/use-col-hidden.js +16 -21
- package/lib/esm/hooks/use-col-set.js +5 -13
- package/lib/esm/hooks/use-col-sorter.js +18 -23
- package/lib/esm/hooks/use-col-width.js +14 -34
- package/lib/esm/hooks/use-colgroup.js +60 -66
- package/lib/esm/hooks/use-drag.js +9 -13
- package/lib/esm/hooks/use-embed-expand.js +20 -42
- package/lib/esm/hooks/use-expand.js +32 -56
- package/lib/esm/hooks/use-pagination.js +13 -25
- package/lib/esm/hooks/use-queue.js +2 -10
- package/lib/esm/node_modules/classnames/index.js +2 -9
- package/lib/esm/node_modules/perfect-scrollbar/dist/perfect-scrollbar.esm.js +31 -228
- package/lib/esm/node_modules/rc-resize-observer/es/index.js +3 -26
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/Children/toArray.js +0 -3
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/Dom/findDOMNode.js +1 -2
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/ref.js +0 -8
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/warning.js +0 -5
- package/lib/esm/node_modules/rc-util/es/Dom/canUseDom.js +0 -1
- package/lib/esm/node_modules/rc-util/es/Dom/findDOMNode.js +1 -2
- package/lib/esm/node_modules/rc-util/es/hooks/useLayoutEffect.js +1 -0
- package/lib/esm/node_modules/rc-util/es/raf.js +0 -10
- package/lib/esm/node_modules/rc-virtual-list/es/Filler.js +4 -15
- package/lib/esm/node_modules/rc-virtual-list/es/Item.js +1 -3
- package/lib/esm/node_modules/rc-virtual-list/es/List.js +101 -174
- package/lib/esm/node_modules/rc-virtual-list/es/ScrollBar.js +14 -86
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useChildren.js +0 -2
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useDiffItem.js +6 -25
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js +0 -6
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useHeights.js +4 -28
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js +0 -13
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useOriginScroll.js +4 -8
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useScrollTo.js +1 -19
- package/lib/esm/node_modules/rc-virtual-list/es/index.js +1 -1
- package/lib/esm/node_modules/rc-virtual-list/es/utils/CacheMap.js +2 -8
- package/lib/esm/node_modules/rc-virtual-list/es/utils/algorithmUtil.js +1 -12
- package/lib/esm/node_modules/rc-virtual-list/es/utils/isFirefox.js +0 -1
- package/lib/esm/node_modules/react-is/cjs/react-is.development.js +4 -27
- package/lib/esm/node_modules/react-is/cjs/react-is.production.min.js +20 -44
- package/lib/esm/node_modules/react-is/index.js +0 -1
- package/lib/esm/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +82 -248
- package/lib/esm/packages/hooks/use-merge-refs/lib/esm/index.js +3 -9
- package/lib/esm/packages/ui/scrollbar/lib/esm/Scrollbar.js +47 -64
- package/lib/esm/packages/ui/scrollbar/lib/esm/styles/index.scss.js +1 -3
- package/lib/esm/packages/ui/scrollbar/lib/esm/utils/index.js +0 -10
- package/lib/esm/styles/index.scss.js +1 -3
- package/lib/esm/use-table.js +261 -318
- package/lib/esm/utils/index.js +11 -41
- package/lib/types/BaseTable.d.ts +2 -2
- package/package.json +33 -33
|
@@ -12,15 +12,14 @@
|
|
|
12
12
|
Object.defineProperty(exports, '__esModule', {
|
|
13
13
|
value: true
|
|
14
14
|
});
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* A collection of shims that provide minimal functionality of the ES6 collections.
|
|
17
18
|
*
|
|
18
19
|
* These implementations are not meant to be used outside of the ResizeObserver
|
|
19
20
|
* modules as they cover only a limited range of use cases.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
22
|
/* eslint-disable require-jsdoc, valid-jsdoc */
|
|
23
|
-
|
|
24
23
|
var MapShim = function () {
|
|
25
24
|
if (typeof Map !== 'undefined') {
|
|
26
25
|
return Map;
|
|
@@ -32,8 +31,6 @@ var MapShim = function () {
|
|
|
32
31
|
* @param {*} key
|
|
33
32
|
* @returns {number}
|
|
34
33
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
34
|
function getIndex(arr, key) {
|
|
38
35
|
var result = -1;
|
|
39
36
|
arr.some(function (entry, index) {
|
|
@@ -41,19 +38,14 @@ var MapShim = function () {
|
|
|
41
38
|
result = index;
|
|
42
39
|
return true;
|
|
43
40
|
}
|
|
44
|
-
|
|
45
41
|
return false;
|
|
46
42
|
});
|
|
47
43
|
return result;
|
|
48
44
|
}
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
/** @class */
|
|
52
|
-
function () {
|
|
45
|
+
return (/** @class */function () {
|
|
53
46
|
function class_1() {
|
|
54
47
|
this.__entries__ = [];
|
|
55
48
|
}
|
|
56
|
-
|
|
57
49
|
Object.defineProperty(class_1.prototype, "size", {
|
|
58
50
|
/**
|
|
59
51
|
* @returns {boolean}
|
|
@@ -68,7 +60,6 @@ var MapShim = function () {
|
|
|
68
60
|
* @param {*} key
|
|
69
61
|
* @returns {*}
|
|
70
62
|
*/
|
|
71
|
-
|
|
72
63
|
class_1.prototype.get = function (key) {
|
|
73
64
|
var index = getIndex(this.__entries__, key);
|
|
74
65
|
var entry = this.__entries__[index];
|
|
@@ -79,11 +70,8 @@ var MapShim = function () {
|
|
|
79
70
|
* @param {*} value
|
|
80
71
|
* @returns {void}
|
|
81
72
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
73
|
class_1.prototype.set = function (key, value) {
|
|
85
74
|
var index = getIndex(this.__entries__, key);
|
|
86
|
-
|
|
87
75
|
if (~index) {
|
|
88
76
|
this.__entries__[index][1] = value;
|
|
89
77
|
} else {
|
|
@@ -94,12 +82,9 @@ var MapShim = function () {
|
|
|
94
82
|
* @param {*} key
|
|
95
83
|
* @returns {void}
|
|
96
84
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
85
|
class_1.prototype["delete"] = function (key) {
|
|
100
86
|
var entries = this.__entries__;
|
|
101
87
|
var index = getIndex(entries, key);
|
|
102
|
-
|
|
103
88
|
if (~index) {
|
|
104
89
|
entries.splice(index, 1);
|
|
105
90
|
}
|
|
@@ -108,16 +93,12 @@ var MapShim = function () {
|
|
|
108
93
|
* @param {*} key
|
|
109
94
|
* @returns {void}
|
|
110
95
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
96
|
class_1.prototype.has = function (key) {
|
|
114
97
|
return !!~getIndex(this.__entries__, key);
|
|
115
98
|
};
|
|
116
99
|
/**
|
|
117
100
|
* @returns {void}
|
|
118
101
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
102
|
class_1.prototype.clear = function () {
|
|
122
103
|
this.__entries__.splice(0);
|
|
123
104
|
};
|
|
@@ -126,54 +107,46 @@ var MapShim = function () {
|
|
|
126
107
|
* @param {*} [ctx=null]
|
|
127
108
|
* @returns {void}
|
|
128
109
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
110
|
class_1.prototype.forEach = function (callback, ctx) {
|
|
132
111
|
if (ctx === void 0) {
|
|
133
112
|
ctx = null;
|
|
134
113
|
}
|
|
135
|
-
|
|
136
114
|
for (var _i = 0, _a = this.__entries__; _i < _a.length; _i++) {
|
|
137
115
|
var entry = _a[_i];
|
|
138
116
|
callback.call(ctx, entry[1], entry[0]);
|
|
139
117
|
}
|
|
140
118
|
};
|
|
141
|
-
|
|
142
119
|
return class_1;
|
|
143
120
|
}()
|
|
144
121
|
);
|
|
145
122
|
}();
|
|
123
|
+
|
|
146
124
|
/**
|
|
147
125
|
* Detects whether window and document objects are available in current environment.
|
|
148
126
|
*/
|
|
127
|
+
var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && window.document === document;
|
|
149
128
|
|
|
150
|
-
|
|
151
|
-
var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && window.document === document; // Returns global object of a current environment.
|
|
152
|
-
|
|
129
|
+
// Returns global object of a current environment.
|
|
153
130
|
var global$1 = function () {
|
|
154
131
|
if (typeof global !== 'undefined' && global.Math === Math) {
|
|
155
132
|
return global;
|
|
156
133
|
}
|
|
157
|
-
|
|
158
134
|
if (typeof self !== 'undefined' && self.Math === Math) {
|
|
159
135
|
return self;
|
|
160
136
|
}
|
|
161
|
-
|
|
162
137
|
if (typeof window !== 'undefined' && window.Math === Math) {
|
|
163
138
|
return window;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
139
|
+
}
|
|
140
|
+
// eslint-disable-next-line no-new-func
|
|
167
141
|
return Function('return this')();
|
|
168
142
|
}();
|
|
143
|
+
|
|
169
144
|
/**
|
|
170
145
|
* A shim for the requestAnimationFrame which falls back to the setTimeout if
|
|
171
146
|
* first one is not supported.
|
|
172
147
|
*
|
|
173
148
|
* @returns {number} Requests' identifier.
|
|
174
149
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
150
|
var requestAnimationFrame$1 = function () {
|
|
178
151
|
if (typeof requestAnimationFrame === 'function') {
|
|
179
152
|
// It's required to use a bounded function because IE sometimes throws
|
|
@@ -181,15 +154,14 @@ var requestAnimationFrame$1 = function () {
|
|
|
181
154
|
// object on the left hand side.
|
|
182
155
|
return requestAnimationFrame.bind(global$1);
|
|
183
156
|
}
|
|
184
|
-
|
|
185
157
|
return function (callback) {
|
|
186
158
|
return setTimeout(function () {
|
|
187
159
|
return callback(Date.now());
|
|
188
160
|
}, 1000 / 60);
|
|
189
161
|
};
|
|
190
|
-
}();
|
|
191
|
-
|
|
162
|
+
}();
|
|
192
163
|
|
|
164
|
+
// Defines minimum timeout before adding a trailing call.
|
|
193
165
|
var trailingTimeout = 2;
|
|
194
166
|
/**
|
|
195
167
|
* Creates a wrapper function which ensures that provided callback will be
|
|
@@ -199,24 +171,21 @@ var trailingTimeout = 2;
|
|
|
199
171
|
* @param {number} delay - Delay after which to invoke callback.
|
|
200
172
|
* @returns {Function}
|
|
201
173
|
*/
|
|
202
|
-
|
|
203
174
|
function throttle(callback, delay) {
|
|
204
175
|
var leadingCall = false,
|
|
205
|
-
|
|
206
|
-
|
|
176
|
+
trailingCall = false,
|
|
177
|
+
lastCallTime = 0;
|
|
207
178
|
/**
|
|
208
179
|
* Invokes the original callback function and schedules new invocation if
|
|
209
180
|
* the "proxy" was called during current request.
|
|
210
181
|
*
|
|
211
182
|
* @returns {void}
|
|
212
183
|
*/
|
|
213
|
-
|
|
214
184
|
function resolvePending() {
|
|
215
185
|
if (leadingCall) {
|
|
216
186
|
leadingCall = false;
|
|
217
187
|
callback();
|
|
218
188
|
}
|
|
219
|
-
|
|
220
189
|
if (trailingCall) {
|
|
221
190
|
proxy();
|
|
222
191
|
}
|
|
@@ -228,8 +197,6 @@ function throttle(callback, delay) {
|
|
|
228
197
|
*
|
|
229
198
|
* @returns {void}
|
|
230
199
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
200
|
function timeoutCallback() {
|
|
234
201
|
requestAnimationFrame$1(resolvePending);
|
|
235
202
|
}
|
|
@@ -238,48 +205,39 @@ function throttle(callback, delay) {
|
|
|
238
205
|
*
|
|
239
206
|
* @returns {void}
|
|
240
207
|
*/
|
|
241
|
-
|
|
242
|
-
|
|
243
208
|
function proxy() {
|
|
244
209
|
var timeStamp = Date.now();
|
|
245
|
-
|
|
246
210
|
if (leadingCall) {
|
|
247
211
|
// Reject immediately following calls.
|
|
248
212
|
if (timeStamp - lastCallTime < trailingTimeout) {
|
|
249
213
|
return;
|
|
250
|
-
}
|
|
214
|
+
}
|
|
215
|
+
// Schedule new call to be in invoked when the pending one is resolved.
|
|
251
216
|
// This is important for "transitions" which never actually start
|
|
252
217
|
// immediately so there is a chance that we might miss one if change
|
|
253
218
|
// happens amids the pending invocation.
|
|
254
|
-
|
|
255
|
-
|
|
256
219
|
trailingCall = true;
|
|
257
220
|
} else {
|
|
258
221
|
leadingCall = true;
|
|
259
222
|
trailingCall = false;
|
|
260
223
|
setTimeout(timeoutCallback, delay);
|
|
261
224
|
}
|
|
262
|
-
|
|
263
225
|
lastCallTime = timeStamp;
|
|
264
226
|
}
|
|
265
|
-
|
|
266
227
|
return proxy;
|
|
267
|
-
}
|
|
268
|
-
|
|
228
|
+
}
|
|
269
229
|
|
|
270
|
-
|
|
230
|
+
// Minimum delay before invoking the update of observers.
|
|
231
|
+
var REFRESH_DELAY = 20;
|
|
232
|
+
// A list of substrings of CSS properties used to find transition events that
|
|
271
233
|
// might affect dimensions of observed elements.
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
234
|
+
var transitionKeys = ['top', 'right', 'bottom', 'left', 'width', 'height', 'size', 'weight'];
|
|
235
|
+
// Check if MutationObserver is available.
|
|
275
236
|
var mutationObserverSupported = typeof MutationObserver !== 'undefined';
|
|
276
237
|
/**
|
|
277
238
|
* Singleton controller class which handles updates of ResizeObserver instances.
|
|
278
239
|
*/
|
|
279
|
-
|
|
280
|
-
var ResizeObserverController =
|
|
281
|
-
/** @class */
|
|
282
|
-
function () {
|
|
240
|
+
var ResizeObserverController = /** @class */function () {
|
|
283
241
|
/**
|
|
284
242
|
* Creates a new instance of ResizeObserverController.
|
|
285
243
|
*
|
|
@@ -297,21 +255,18 @@ function () {
|
|
|
297
255
|
*
|
|
298
256
|
* @private {boolean}
|
|
299
257
|
*/
|
|
300
|
-
|
|
301
258
|
this.mutationEventsAdded_ = false;
|
|
302
259
|
/**
|
|
303
260
|
* Keeps reference to the instance of MutationObserver.
|
|
304
261
|
*
|
|
305
262
|
* @private {MutationObserver}
|
|
306
263
|
*/
|
|
307
|
-
|
|
308
264
|
this.mutationsObserver_ = null;
|
|
309
265
|
/**
|
|
310
266
|
* A list of connected observers.
|
|
311
267
|
*
|
|
312
268
|
* @private {Array<ResizeObserverSPI>}
|
|
313
269
|
*/
|
|
314
|
-
|
|
315
270
|
this.observers_ = [];
|
|
316
271
|
this.onTransitionEnd_ = this.onTransitionEnd_.bind(this);
|
|
317
272
|
this.refresh = throttle(this.refresh.bind(this), REFRESH_DELAY);
|
|
@@ -322,14 +277,11 @@ function () {
|
|
|
322
277
|
* @param {ResizeObserverSPI} observer - Observer to be added.
|
|
323
278
|
* @returns {void}
|
|
324
279
|
*/
|
|
325
|
-
|
|
326
|
-
|
|
327
280
|
ResizeObserverController.prototype.addObserver = function (observer) {
|
|
328
281
|
if (!~this.observers_.indexOf(observer)) {
|
|
329
282
|
this.observers_.push(observer);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
283
|
+
}
|
|
284
|
+
// Add listeners if they haven't been added yet.
|
|
333
285
|
if (!this.connected_) {
|
|
334
286
|
this.connect_();
|
|
335
287
|
}
|
|
@@ -340,17 +292,14 @@ function () {
|
|
|
340
292
|
* @param {ResizeObserverSPI} observer - Observer to be removed.
|
|
341
293
|
* @returns {void}
|
|
342
294
|
*/
|
|
343
|
-
|
|
344
|
-
|
|
345
295
|
ResizeObserverController.prototype.removeObserver = function (observer) {
|
|
346
296
|
var observers = this.observers_;
|
|
347
|
-
var index = observers.indexOf(observer);
|
|
348
|
-
|
|
297
|
+
var index = observers.indexOf(observer);
|
|
298
|
+
// Remove observer if it's present in registry.
|
|
349
299
|
if (~index) {
|
|
350
300
|
observers.splice(index, 1);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
301
|
+
}
|
|
302
|
+
// Remove listeners if controller has no connected observers.
|
|
354
303
|
if (!observers.length && this.connected_) {
|
|
355
304
|
this.disconnect_();
|
|
356
305
|
}
|
|
@@ -361,12 +310,10 @@ function () {
|
|
|
361
310
|
*
|
|
362
311
|
* @returns {void}
|
|
363
312
|
*/
|
|
364
|
-
|
|
365
|
-
|
|
366
313
|
ResizeObserverController.prototype.refresh = function () {
|
|
367
|
-
var changesDetected = this.updateObservers_();
|
|
314
|
+
var changesDetected = this.updateObservers_();
|
|
315
|
+
// Continue running updates if changes have been detected as there might
|
|
368
316
|
// be future ones caused by CSS transitions.
|
|
369
|
-
|
|
370
317
|
if (changesDetected) {
|
|
371
318
|
this.refresh();
|
|
372
319
|
}
|
|
@@ -379,18 +326,16 @@ function () {
|
|
|
379
326
|
* @returns {boolean} Returns "true" if any observer has detected changes in
|
|
380
327
|
* dimensions of it's elements.
|
|
381
328
|
*/
|
|
382
|
-
|
|
383
|
-
|
|
384
329
|
ResizeObserverController.prototype.updateObservers_ = function () {
|
|
385
330
|
// Collect observers that have active observations.
|
|
386
331
|
var activeObservers = this.observers_.filter(function (observer) {
|
|
387
332
|
return observer.gatherActive(), observer.hasActive();
|
|
388
|
-
});
|
|
333
|
+
});
|
|
334
|
+
// Deliver notifications in a separate cycle in order to avoid any
|
|
389
335
|
// collisions between observers, e.g. when multiple instances of
|
|
390
336
|
// ResizeObserver are tracking the same element and the callback of one
|
|
391
337
|
// of them changes content dimensions of the observed target. Sometimes
|
|
392
338
|
// this may result in notifications being blocked for the rest of observers.
|
|
393
|
-
|
|
394
339
|
activeObservers.forEach(function (observer) {
|
|
395
340
|
return observer.broadcastActive();
|
|
396
341
|
});
|
|
@@ -402,21 +347,17 @@ function () {
|
|
|
402
347
|
* @private
|
|
403
348
|
* @returns {void}
|
|
404
349
|
*/
|
|
405
|
-
|
|
406
|
-
|
|
407
350
|
ResizeObserverController.prototype.connect_ = function () {
|
|
408
351
|
// Do nothing if running in a non-browser environment or if listeners
|
|
409
352
|
// have been already added.
|
|
410
353
|
if (!isBrowser || this.connected_) {
|
|
411
354
|
return;
|
|
412
|
-
}
|
|
355
|
+
}
|
|
356
|
+
// Subscription to the "Transitionend" event is used as a workaround for
|
|
413
357
|
// delayed transitions. This way it's possible to capture at least the
|
|
414
358
|
// final state of an element.
|
|
415
|
-
|
|
416
|
-
|
|
417
359
|
document.addEventListener('transitionend', this.onTransitionEnd_);
|
|
418
360
|
window.addEventListener('resize', this.refresh);
|
|
419
|
-
|
|
420
361
|
if (mutationObserverSupported) {
|
|
421
362
|
this.mutationsObserver_ = new MutationObserver(this.refresh);
|
|
422
363
|
this.mutationsObserver_.observe(document, {
|
|
@@ -429,7 +370,6 @@ function () {
|
|
|
429
370
|
document.addEventListener('DOMSubtreeModified', this.refresh);
|
|
430
371
|
this.mutationEventsAdded_ = true;
|
|
431
372
|
}
|
|
432
|
-
|
|
433
373
|
this.connected_ = true;
|
|
434
374
|
};
|
|
435
375
|
/**
|
|
@@ -438,26 +378,20 @@ function () {
|
|
|
438
378
|
* @private
|
|
439
379
|
* @returns {void}
|
|
440
380
|
*/
|
|
441
|
-
|
|
442
|
-
|
|
443
381
|
ResizeObserverController.prototype.disconnect_ = function () {
|
|
444
382
|
// Do nothing if running in a non-browser environment or if listeners
|
|
445
383
|
// have been already removed.
|
|
446
384
|
if (!isBrowser || !this.connected_) {
|
|
447
385
|
return;
|
|
448
386
|
}
|
|
449
|
-
|
|
450
387
|
document.removeEventListener('transitionend', this.onTransitionEnd_);
|
|
451
388
|
window.removeEventListener('resize', this.refresh);
|
|
452
|
-
|
|
453
389
|
if (this.mutationsObserver_) {
|
|
454
390
|
this.mutationsObserver_.disconnect();
|
|
455
391
|
}
|
|
456
|
-
|
|
457
392
|
if (this.mutationEventsAdded_) {
|
|
458
393
|
document.removeEventListener('DOMSubtreeModified', this.refresh);
|
|
459
394
|
}
|
|
460
|
-
|
|
461
395
|
this.mutationsObserver_ = null;
|
|
462
396
|
this.mutationEventsAdded_ = false;
|
|
463
397
|
this.connected_ = false;
|
|
@@ -469,16 +403,13 @@ function () {
|
|
|
469
403
|
* @param {TransitionEvent} event
|
|
470
404
|
* @returns {void}
|
|
471
405
|
*/
|
|
472
|
-
|
|
473
|
-
|
|
474
406
|
ResizeObserverController.prototype.onTransitionEnd_ = function (_a) {
|
|
475
407
|
var _b = _a.propertyName,
|
|
476
|
-
|
|
477
|
-
|
|
408
|
+
propertyName = _b === void 0 ? '' : _b;
|
|
409
|
+
// Detect whether transition may affect dimensions of an element.
|
|
478
410
|
var isReflowProperty = transitionKeys.some(function (key) {
|
|
479
411
|
return !!~propertyName.indexOf(key);
|
|
480
412
|
});
|
|
481
|
-
|
|
482
413
|
if (isReflowProperty) {
|
|
483
414
|
this.refresh();
|
|
484
415
|
}
|
|
@@ -488,13 +419,10 @@ function () {
|
|
|
488
419
|
*
|
|
489
420
|
* @returns {ResizeObserverController}
|
|
490
421
|
*/
|
|
491
|
-
|
|
492
|
-
|
|
493
422
|
ResizeObserverController.getInstance = function () {
|
|
494
423
|
if (!this.instance_) {
|
|
495
424
|
this.instance_ = new ResizeObserverController();
|
|
496
425
|
}
|
|
497
|
-
|
|
498
426
|
return this.instance_;
|
|
499
427
|
};
|
|
500
428
|
/**
|
|
@@ -502,11 +430,10 @@ function () {
|
|
|
502
430
|
*
|
|
503
431
|
* @private {ResizeObserverController}
|
|
504
432
|
*/
|
|
505
|
-
|
|
506
|
-
|
|
507
433
|
ResizeObserverController.instance_ = null;
|
|
508
434
|
return ResizeObserverController;
|
|
509
435
|
}();
|
|
436
|
+
|
|
510
437
|
/**
|
|
511
438
|
* Defines non-writable/enumerable properties of the provided target object.
|
|
512
439
|
*
|
|
@@ -514,8 +441,6 @@ function () {
|
|
|
514
441
|
* @param {Object} props - Properties to be defined.
|
|
515
442
|
* @returns {Object} Target object.
|
|
516
443
|
*/
|
|
517
|
-
|
|
518
|
-
|
|
519
444
|
var defineConfigurable = function defineConfigurable(target, props) {
|
|
520
445
|
for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) {
|
|
521
446
|
var key = _a[_i];
|
|
@@ -526,28 +451,26 @@ var defineConfigurable = function defineConfigurable(target, props) {
|
|
|
526
451
|
configurable: true
|
|
527
452
|
});
|
|
528
453
|
}
|
|
529
|
-
|
|
530
454
|
return target;
|
|
531
455
|
};
|
|
456
|
+
|
|
532
457
|
/**
|
|
533
458
|
* Returns the global object associated with provided element.
|
|
534
459
|
*
|
|
535
460
|
* @param {Object} target
|
|
536
461
|
* @returns {Object}
|
|
537
462
|
*/
|
|
538
|
-
|
|
539
|
-
|
|
540
463
|
var getWindowOf = function getWindowOf(target) {
|
|
541
464
|
// Assume that the element is an instance of Node, which means that it
|
|
542
465
|
// has the "ownerDocument" property from which we can retrieve a
|
|
543
466
|
// corresponding global object.
|
|
544
|
-
var ownerGlobal = target && target.ownerDocument && target.ownerDocument.defaultView;
|
|
467
|
+
var ownerGlobal = target && target.ownerDocument && target.ownerDocument.defaultView;
|
|
468
|
+
// Return the local global object if it's not possible extract one from
|
|
545
469
|
// provided element.
|
|
546
|
-
|
|
547
470
|
return ownerGlobal || global$1;
|
|
548
|
-
};
|
|
549
|
-
|
|
471
|
+
};
|
|
550
472
|
|
|
473
|
+
// Placeholder of an empty content rectangle.
|
|
551
474
|
var emptyRect = createRectInit(0, 0, 0, 0);
|
|
552
475
|
/**
|
|
553
476
|
* Converts provided string to a number.
|
|
@@ -555,7 +478,6 @@ var emptyRect = createRectInit(0, 0, 0, 0);
|
|
|
555
478
|
* @param {number|string} value
|
|
556
479
|
* @returns {number}
|
|
557
480
|
*/
|
|
558
|
-
|
|
559
481
|
function toFloat(value) {
|
|
560
482
|
return parseFloat(value) || 0;
|
|
561
483
|
}
|
|
@@ -566,15 +488,11 @@ function toFloat(value) {
|
|
|
566
488
|
* @param {...string} positions - Borders positions (top, right, ...)
|
|
567
489
|
* @returns {number}
|
|
568
490
|
*/
|
|
569
|
-
|
|
570
|
-
|
|
571
491
|
function getBordersSize(styles) {
|
|
572
492
|
var positions = [];
|
|
573
|
-
|
|
574
493
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
575
494
|
positions[_i - 1] = arguments[_i];
|
|
576
495
|
}
|
|
577
|
-
|
|
578
496
|
return positions.reduce(function (size, position) {
|
|
579
497
|
var value = styles['border-' + position + '-width'];
|
|
580
498
|
return size + toFloat(value);
|
|
@@ -586,18 +504,14 @@ function getBordersSize(styles) {
|
|
|
586
504
|
* @param {CSSStyleDeclaration} styles
|
|
587
505
|
* @returns {Object} Paddings box.
|
|
588
506
|
*/
|
|
589
|
-
|
|
590
|
-
|
|
591
507
|
function getPaddings(styles) {
|
|
592
508
|
var positions = ['top', 'right', 'bottom', 'left'];
|
|
593
509
|
var paddings = {};
|
|
594
|
-
|
|
595
510
|
for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) {
|
|
596
511
|
var position = positions_1[_i];
|
|
597
512
|
var value = styles['padding-' + position];
|
|
598
513
|
paddings[position] = toFloat(value);
|
|
599
514
|
}
|
|
600
|
-
|
|
601
515
|
return paddings;
|
|
602
516
|
}
|
|
603
517
|
/**
|
|
@@ -607,8 +521,6 @@ function getPaddings(styles) {
|
|
|
607
521
|
* to be calculated.
|
|
608
522
|
* @returns {DOMRectInit}
|
|
609
523
|
*/
|
|
610
|
-
|
|
611
|
-
|
|
612
524
|
function getSVGContentRect(target) {
|
|
613
525
|
var bbox = target.getBBox();
|
|
614
526
|
return createRectInit(0, 0, bbox.width, bbox.height);
|
|
@@ -619,13 +531,12 @@ function getSVGContentRect(target) {
|
|
|
619
531
|
* @param {HTMLElement} target - Element for which to calculate the content rectangle.
|
|
620
532
|
* @returns {DOMRectInit}
|
|
621
533
|
*/
|
|
622
|
-
|
|
623
|
-
|
|
624
534
|
function getHTMLElementContentRect(target) {
|
|
625
535
|
// Client width & height properties can't be
|
|
626
536
|
// used exclusively as they provide rounded values.
|
|
627
537
|
var clientWidth = target.clientWidth,
|
|
628
|
-
|
|
538
|
+
clientHeight = target.clientHeight;
|
|
539
|
+
// By this condition we can catch all non-replaced inline, hidden and
|
|
629
540
|
// detached elements. Though elements with width & height properties less
|
|
630
541
|
// than 0.5 will be discarded as well.
|
|
631
542
|
//
|
|
@@ -633,23 +544,21 @@ function getHTMLElementContentRect(target) {
|
|
|
633
544
|
// those cases and it's not possible to perform a precise and performance
|
|
634
545
|
// effective test for hidden elements. E.g. even jQuery's ':visible' filter
|
|
635
546
|
// gives wrong results for elements with width & height less than 0.5.
|
|
636
|
-
|
|
637
547
|
if (!clientWidth && !clientHeight) {
|
|
638
548
|
return emptyRect;
|
|
639
549
|
}
|
|
640
|
-
|
|
641
550
|
var styles = getWindowOf(target).getComputedStyle(target);
|
|
642
551
|
var paddings = getPaddings(styles);
|
|
643
552
|
var horizPad = paddings.left + paddings.right;
|
|
644
|
-
var vertPad = paddings.top + paddings.bottom;
|
|
553
|
+
var vertPad = paddings.top + paddings.bottom;
|
|
554
|
+
// Computed styles of width & height are being used because they are the
|
|
645
555
|
// only dimensions available to JS that contain non-rounded values. It could
|
|
646
556
|
// be possible to utilize the getBoundingClientRect if only it's data wasn't
|
|
647
557
|
// affected by CSS transformations let alone paddings, borders and scroll bars.
|
|
648
|
-
|
|
649
558
|
var width = toFloat(styles.width),
|
|
650
|
-
|
|
559
|
+
height = toFloat(styles.height);
|
|
560
|
+
// Width & height include paddings and borders when the 'border-box' box
|
|
651
561
|
// model is applied (except for IE).
|
|
652
|
-
|
|
653
562
|
if (styles.boxSizing === 'border-box') {
|
|
654
563
|
// Following conditions are required to handle Internet Explorer which
|
|
655
564
|
// doesn't include paddings and borders to computed CSS dimensions.
|
|
@@ -660,37 +569,33 @@ function getHTMLElementContentRect(target) {
|
|
|
660
569
|
if (Math.round(width + horizPad) !== clientWidth) {
|
|
661
570
|
width -= getBordersSize(styles, 'left', 'right') + horizPad;
|
|
662
571
|
}
|
|
663
|
-
|
|
664
572
|
if (Math.round(height + vertPad) !== clientHeight) {
|
|
665
573
|
height -= getBordersSize(styles, 'top', 'bottom') + vertPad;
|
|
666
574
|
}
|
|
667
|
-
}
|
|
575
|
+
}
|
|
576
|
+
// Following steps can't be applied to the document's root element as its
|
|
668
577
|
// client[Width/Height] properties represent viewport area of the window.
|
|
669
578
|
// Besides, it's as well not necessary as the <html> itself neither has
|
|
670
579
|
// rendered scroll bars nor it can be clipped.
|
|
671
|
-
|
|
672
|
-
|
|
673
580
|
if (!isDocumentElement(target)) {
|
|
674
581
|
// In some browsers (only in Firefox, actually) CSS width & height
|
|
675
582
|
// include scroll bars size which can be removed at this step as scroll
|
|
676
583
|
// bars are the only difference between rounded dimensions + paddings
|
|
677
584
|
// and "client" properties, though that is not always true in Chrome.
|
|
678
585
|
var vertScrollbar = Math.round(width + horizPad) - clientWidth;
|
|
679
|
-
var horizScrollbar = Math.round(height + vertPad) - clientHeight;
|
|
586
|
+
var horizScrollbar = Math.round(height + vertPad) - clientHeight;
|
|
587
|
+
// Chrome has a rather weird rounding of "client" properties.
|
|
680
588
|
// E.g. for an element with content width of 314.2px it sometimes gives
|
|
681
589
|
// the client width of 315px and for the width of 314.7px it may give
|
|
682
590
|
// 314px. And it doesn't happen all the time. So just ignore this delta
|
|
683
591
|
// as a non-relevant.
|
|
684
|
-
|
|
685
592
|
if (Math.abs(vertScrollbar) !== 1) {
|
|
686
593
|
width -= vertScrollbar;
|
|
687
594
|
}
|
|
688
|
-
|
|
689
595
|
if (Math.abs(horizScrollbar) !== 1) {
|
|
690
596
|
height -= horizScrollbar;
|
|
691
597
|
}
|
|
692
598
|
}
|
|
693
|
-
|
|
694
599
|
return createRectInit(paddings.left, paddings.top, width, height);
|
|
695
600
|
}
|
|
696
601
|
/**
|
|
@@ -699,8 +604,6 @@ function getHTMLElementContentRect(target) {
|
|
|
699
604
|
* @param {Element} target - Element to be checked.
|
|
700
605
|
* @returns {boolean}
|
|
701
606
|
*/
|
|
702
|
-
|
|
703
|
-
|
|
704
607
|
var isSVGGraphicsElement = function () {
|
|
705
608
|
// Some browsers, namely IE and Edge, don't have the SVGGraphicsElement
|
|
706
609
|
// interface.
|
|
@@ -708,11 +611,10 @@ var isSVGGraphicsElement = function () {
|
|
|
708
611
|
return function (target) {
|
|
709
612
|
return target instanceof getWindowOf(target).SVGGraphicsElement;
|
|
710
613
|
};
|
|
711
|
-
}
|
|
614
|
+
}
|
|
615
|
+
// If it's so, then check that element is at least an instance of the
|
|
712
616
|
// SVGElement and that it has the "getBBox" method.
|
|
713
617
|
// eslint-disable-next-line no-extra-parens
|
|
714
|
-
|
|
715
|
-
|
|
716
618
|
return function (target) {
|
|
717
619
|
return target instanceof getWindowOf(target).SVGElement && typeof target.getBBox === 'function';
|
|
718
620
|
};
|
|
@@ -723,8 +625,6 @@ var isSVGGraphicsElement = function () {
|
|
|
723
625
|
* @param {Element} target - Element to be checked.
|
|
724
626
|
* @returns {boolean}
|
|
725
627
|
*/
|
|
726
|
-
|
|
727
|
-
|
|
728
628
|
function isDocumentElement(target) {
|
|
729
629
|
return target === getWindowOf(target).document.documentElement;
|
|
730
630
|
}
|
|
@@ -734,17 +634,13 @@ function isDocumentElement(target) {
|
|
|
734
634
|
* @param {Element} target - Element content rectangle of which needs to be calculated.
|
|
735
635
|
* @returns {DOMRectInit}
|
|
736
636
|
*/
|
|
737
|
-
|
|
738
|
-
|
|
739
637
|
function getContentRect(target) {
|
|
740
638
|
if (!isBrowser) {
|
|
741
639
|
return emptyRect;
|
|
742
640
|
}
|
|
743
|
-
|
|
744
641
|
if (isSVGGraphicsElement(target)) {
|
|
745
642
|
return getSVGContentRect(target);
|
|
746
643
|
}
|
|
747
|
-
|
|
748
644
|
return getHTMLElementContentRect(target);
|
|
749
645
|
}
|
|
750
646
|
/**
|
|
@@ -754,17 +650,15 @@ function getContentRect(target) {
|
|
|
754
650
|
* @param {DOMRectInit} rectInit - Object with rectangle's x/y coordinates and dimensions.
|
|
755
651
|
* @returns {DOMRectReadOnly}
|
|
756
652
|
*/
|
|
757
|
-
|
|
758
|
-
|
|
759
653
|
function createReadOnlyRect(_a) {
|
|
760
654
|
var x = _a.x,
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
655
|
+
y = _a.y,
|
|
656
|
+
width = _a.width,
|
|
657
|
+
height = _a.height;
|
|
658
|
+
// If DOMRectReadOnly is available use it as a prototype for the rectangle.
|
|
765
659
|
var Constr = typeof DOMRectReadOnly !== 'undefined' ? DOMRectReadOnly : Object;
|
|
766
|
-
var rect = Object.create(Constr.prototype);
|
|
767
|
-
|
|
660
|
+
var rect = Object.create(Constr.prototype);
|
|
661
|
+
// Rectangle's properties are not writable and non-enumerable.
|
|
768
662
|
defineConfigurable(rect, {
|
|
769
663
|
x: x,
|
|
770
664
|
y: y,
|
|
@@ -787,8 +681,6 @@ function createReadOnlyRect(_a) {
|
|
|
787
681
|
* @param {number} height - Rectangle's height.
|
|
788
682
|
* @returns {DOMRectInit}
|
|
789
683
|
*/
|
|
790
|
-
|
|
791
|
-
|
|
792
684
|
function createRectInit(x, y, width, height) {
|
|
793
685
|
return {
|
|
794
686
|
x: x,
|
|
@@ -797,15 +689,12 @@ function createRectInit(x, y, width, height) {
|
|
|
797
689
|
height: height
|
|
798
690
|
};
|
|
799
691
|
}
|
|
692
|
+
|
|
800
693
|
/**
|
|
801
694
|
* Class that is responsible for computations of the content rectangle of
|
|
802
695
|
* provided DOM element and for keeping track of it's changes.
|
|
803
696
|
*/
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
var ResizeObservation =
|
|
807
|
-
/** @class */
|
|
808
|
-
function () {
|
|
697
|
+
var ResizeObservation = /** @class */function () {
|
|
809
698
|
/**
|
|
810
699
|
* Creates an instance of ResizeObservation.
|
|
811
700
|
*
|
|
@@ -823,14 +712,12 @@ function () {
|
|
|
823
712
|
*
|
|
824
713
|
* @type {number}
|
|
825
714
|
*/
|
|
826
|
-
|
|
827
715
|
this.broadcastHeight = 0;
|
|
828
716
|
/**
|
|
829
717
|
* Reference to the last observed content rectangle.
|
|
830
718
|
*
|
|
831
719
|
* @private {DOMRectInit}
|
|
832
720
|
*/
|
|
833
|
-
|
|
834
721
|
this.contentRect_ = createRectInit(0, 0, 0, 0);
|
|
835
722
|
this.target = target;
|
|
836
723
|
}
|
|
@@ -840,8 +727,6 @@ function () {
|
|
|
840
727
|
*
|
|
841
728
|
* @returns {boolean}
|
|
842
729
|
*/
|
|
843
|
-
|
|
844
|
-
|
|
845
730
|
ResizeObservation.prototype.isActive = function () {
|
|
846
731
|
var rect = getContentRect(this.target);
|
|
847
732
|
this.contentRect_ = rect;
|
|
@@ -853,21 +738,15 @@ function () {
|
|
|
853
738
|
*
|
|
854
739
|
* @returns {DOMRectInit} Last observed content rectangle.
|
|
855
740
|
*/
|
|
856
|
-
|
|
857
|
-
|
|
858
741
|
ResizeObservation.prototype.broadcastRect = function () {
|
|
859
742
|
var rect = this.contentRect_;
|
|
860
743
|
this.broadcastWidth = rect.width;
|
|
861
744
|
this.broadcastHeight = rect.height;
|
|
862
745
|
return rect;
|
|
863
746
|
};
|
|
864
|
-
|
|
865
747
|
return ResizeObservation;
|
|
866
748
|
}();
|
|
867
|
-
|
|
868
|
-
var ResizeObserverEntry =
|
|
869
|
-
/** @class */
|
|
870
|
-
function () {
|
|
749
|
+
var ResizeObserverEntry = /** @class */function () {
|
|
871
750
|
/**
|
|
872
751
|
* Creates an instance of ResizeObserverEntry.
|
|
873
752
|
*
|
|
@@ -875,25 +754,21 @@ function () {
|
|
|
875
754
|
* @param {DOMRectInit} rectInit - Data of the element's content rectangle.
|
|
876
755
|
*/
|
|
877
756
|
function ResizeObserverEntry(target, rectInit) {
|
|
878
|
-
var contentRect = createReadOnlyRect(rectInit);
|
|
757
|
+
var contentRect = createReadOnlyRect(rectInit);
|
|
758
|
+
// According to the specification following properties are not writable
|
|
879
759
|
// and are also not enumerable in the native implementation.
|
|
880
760
|
//
|
|
881
761
|
// Property accessors are not being used as they'd require to define a
|
|
882
762
|
// private WeakMap storage which may cause memory leaks in browsers that
|
|
883
763
|
// don't support this type of collections.
|
|
884
|
-
|
|
885
764
|
defineConfigurable(this, {
|
|
886
765
|
target: target,
|
|
887
766
|
contentRect: contentRect
|
|
888
767
|
});
|
|
889
768
|
}
|
|
890
|
-
|
|
891
769
|
return ResizeObserverEntry;
|
|
892
770
|
}();
|
|
893
|
-
|
|
894
|
-
var ResizeObserverSPI =
|
|
895
|
-
/** @class */
|
|
896
|
-
function () {
|
|
771
|
+
var ResizeObserverSPI = /** @class */function () {
|
|
897
772
|
/**
|
|
898
773
|
* Creates a new instance of ResizeObserver.
|
|
899
774
|
*
|
|
@@ -917,13 +792,10 @@ function () {
|
|
|
917
792
|
*
|
|
918
793
|
* @private {Map<Element, ResizeObservation>}
|
|
919
794
|
*/
|
|
920
|
-
|
|
921
795
|
this.observations_ = new MapShim();
|
|
922
|
-
|
|
923
796
|
if (typeof callback !== 'function') {
|
|
924
797
|
throw new TypeError('The callback provided as parameter 1 is not a function.');
|
|
925
798
|
}
|
|
926
|
-
|
|
927
799
|
this.callback_ = callback;
|
|
928
800
|
this.controller_ = controller;
|
|
929
801
|
this.callbackCtx_ = callbackCtx;
|
|
@@ -934,31 +806,25 @@ function () {
|
|
|
934
806
|
* @param {Element} target - Element to be observed.
|
|
935
807
|
* @returns {void}
|
|
936
808
|
*/
|
|
937
|
-
|
|
938
|
-
|
|
939
809
|
ResizeObserverSPI.prototype.observe = function (target) {
|
|
940
810
|
if (!arguments.length) {
|
|
941
811
|
throw new TypeError('1 argument required, but only 0 present.');
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
|
|
812
|
+
}
|
|
813
|
+
// Do nothing if current environment doesn't have the Element interface.
|
|
945
814
|
if (typeof Element === 'undefined' || !(Element instanceof Object)) {
|
|
946
815
|
return;
|
|
947
816
|
}
|
|
948
|
-
|
|
949
817
|
if (!(target instanceof getWindowOf(target).Element)) {
|
|
950
818
|
throw new TypeError('parameter 1 is not of type "Element".');
|
|
951
819
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
820
|
+
var observations = this.observations_;
|
|
821
|
+
// Do nothing if element is already being observed.
|
|
955
822
|
if (observations.has(target)) {
|
|
956
823
|
return;
|
|
957
824
|
}
|
|
958
|
-
|
|
959
825
|
observations.set(target, new ResizeObservation(target));
|
|
960
|
-
this.controller_.addObserver(this);
|
|
961
|
-
|
|
826
|
+
this.controller_.addObserver(this);
|
|
827
|
+
// Force the update of observations.
|
|
962
828
|
this.controller_.refresh();
|
|
963
829
|
};
|
|
964
830
|
/**
|
|
@@ -967,30 +833,23 @@ function () {
|
|
|
967
833
|
* @param {Element} target - Element to stop observing.
|
|
968
834
|
* @returns {void}
|
|
969
835
|
*/
|
|
970
|
-
|
|
971
|
-
|
|
972
836
|
ResizeObserverSPI.prototype.unobserve = function (target) {
|
|
973
837
|
if (!arguments.length) {
|
|
974
838
|
throw new TypeError('1 argument required, but only 0 present.');
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
|
|
839
|
+
}
|
|
840
|
+
// Do nothing if current environment doesn't have the Element interface.
|
|
978
841
|
if (typeof Element === 'undefined' || !(Element instanceof Object)) {
|
|
979
842
|
return;
|
|
980
843
|
}
|
|
981
|
-
|
|
982
844
|
if (!(target instanceof getWindowOf(target).Element)) {
|
|
983
845
|
throw new TypeError('parameter 1 is not of type "Element".');
|
|
984
846
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
847
|
+
var observations = this.observations_;
|
|
848
|
+
// Do nothing if element is not being observed.
|
|
988
849
|
if (!observations.has(target)) {
|
|
989
850
|
return;
|
|
990
851
|
}
|
|
991
|
-
|
|
992
852
|
observations["delete"](target);
|
|
993
|
-
|
|
994
853
|
if (!observations.size) {
|
|
995
854
|
this.controller_.removeObserver(this);
|
|
996
855
|
}
|
|
@@ -1000,8 +859,6 @@ function () {
|
|
|
1000
859
|
*
|
|
1001
860
|
* @returns {void}
|
|
1002
861
|
*/
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
862
|
ResizeObserverSPI.prototype.disconnect = function () {
|
|
1006
863
|
this.clearActive();
|
|
1007
864
|
this.observations_.clear();
|
|
@@ -1013,11 +870,8 @@ function () {
|
|
|
1013
870
|
*
|
|
1014
871
|
* @returns {void}
|
|
1015
872
|
*/
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
873
|
ResizeObserverSPI.prototype.gatherActive = function () {
|
|
1019
874
|
var _this = this;
|
|
1020
|
-
|
|
1021
875
|
this.clearActive();
|
|
1022
876
|
this.observations_.forEach(function (observation) {
|
|
1023
877
|
if (observation.isActive()) {
|
|
@@ -1031,16 +885,13 @@ function () {
|
|
|
1031
885
|
*
|
|
1032
886
|
* @returns {void}
|
|
1033
887
|
*/
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
888
|
ResizeObserverSPI.prototype.broadcastActive = function () {
|
|
1037
889
|
// Do nothing if observer doesn't have active observations.
|
|
1038
890
|
if (!this.hasActive()) {
|
|
1039
891
|
return;
|
|
1040
892
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
893
|
+
var ctx = this.callbackCtx_;
|
|
894
|
+
// Create ResizeObserverEntry instance for every active observation.
|
|
1044
895
|
var entries = this.activeObservations_.map(function (observation) {
|
|
1045
896
|
return new ResizeObserverEntry(observation.target, observation.broadcastRect());
|
|
1046
897
|
});
|
|
@@ -1052,8 +903,6 @@ function () {
|
|
|
1052
903
|
*
|
|
1053
904
|
* @returns {void}
|
|
1054
905
|
*/
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
906
|
ResizeObserverSPI.prototype.clearActive = function () {
|
|
1058
907
|
this.activeObservations_.splice(0);
|
|
1059
908
|
};
|
|
@@ -1062,27 +911,21 @@ function () {
|
|
|
1062
911
|
*
|
|
1063
912
|
* @returns {boolean}
|
|
1064
913
|
*/
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
914
|
ResizeObserverSPI.prototype.hasActive = function () {
|
|
1068
915
|
return this.activeObservations_.length > 0;
|
|
1069
916
|
};
|
|
1070
|
-
|
|
1071
917
|
return ResizeObserverSPI;
|
|
1072
|
-
}();
|
|
918
|
+
}();
|
|
919
|
+
|
|
920
|
+
// Registry of internal observers. If WeakMap is not available use current shim
|
|
1073
921
|
// for the Map collection as it has all required methods and because WeakMap
|
|
1074
922
|
// can't be fully polyfilled anyway.
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
923
|
var observers = typeof WeakMap !== 'undefined' ? new WeakMap() : new MapShim();
|
|
1078
924
|
/**
|
|
1079
925
|
* ResizeObserver API. Encapsulates the ResizeObserver SPI implementation
|
|
1080
926
|
* exposing only those methods and properties that are defined in the spec.
|
|
1081
927
|
*/
|
|
1082
|
-
|
|
1083
|
-
var ResizeObserver =
|
|
1084
|
-
/** @class */
|
|
1085
|
-
function () {
|
|
928
|
+
var ResizeObserver = /** @class */function () {
|
|
1086
929
|
/**
|
|
1087
930
|
* Creates a new instance of ResizeObserver.
|
|
1088
931
|
*
|
|
@@ -1093,35 +936,27 @@ function () {
|
|
|
1093
936
|
if (!(this instanceof ResizeObserver)) {
|
|
1094
937
|
throw new TypeError('Cannot call a class as a function.');
|
|
1095
938
|
}
|
|
1096
|
-
|
|
1097
939
|
if (!arguments.length) {
|
|
1098
940
|
throw new TypeError('1 argument required, but only 0 present.');
|
|
1099
941
|
}
|
|
1100
|
-
|
|
1101
942
|
var controller = ResizeObserverController.getInstance();
|
|
1102
943
|
var observer = new ResizeObserverSPI(callback, controller, this);
|
|
1103
944
|
observers.set(this, observer);
|
|
1104
945
|
}
|
|
1105
|
-
|
|
1106
946
|
return ResizeObserver;
|
|
1107
|
-
}();
|
|
1108
|
-
|
|
1109
|
-
|
|
947
|
+
}();
|
|
948
|
+
// Expose public methods of ResizeObserver.
|
|
1110
949
|
['observe', 'unobserve', 'disconnect'].forEach(function (method) {
|
|
1111
950
|
ResizeObserver.prototype[method] = function () {
|
|
1112
951
|
var _a;
|
|
1113
|
-
|
|
1114
952
|
return (_a = observers.get(this))[method].apply(_a, arguments);
|
|
1115
953
|
};
|
|
1116
954
|
});
|
|
1117
|
-
|
|
1118
955
|
var index = function () {
|
|
1119
956
|
// Export existing implementation if available.
|
|
1120
957
|
if (typeof global$1.ResizeObserver !== 'undefined') {
|
|
1121
958
|
return global$1.ResizeObserver;
|
|
1122
959
|
}
|
|
1123
|
-
|
|
1124
960
|
return ResizeObserver;
|
|
1125
961
|
}();
|
|
1126
|
-
|
|
1127
962
|
exports["default"] = index;
|