@oat-sa/tao-core-ui 3.18.7 → 3.19.0
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/dist/resizeObserver.js +91 -0
- package/package.json +1 -1
- package/src/resizeObserver.js +89 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
define(['jquery'], function ($) { 'use strict';
|
|
2
|
+
|
|
3
|
+
$ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This program is free software; you can redistribute it and/or
|
|
7
|
+
* modify it under the terms of the GNU General Public License
|
|
8
|
+
* as published by the Free Software Foundation; under version 2
|
|
9
|
+
* of the License (non-upgradable).
|
|
10
|
+
*
|
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU General Public License
|
|
17
|
+
* along with this program; if not, write to the Free Software
|
|
18
|
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
19
|
+
*
|
|
20
|
+
* Copyright (c) 2026 (original work) Open Assessment Technologies SA ;
|
|
21
|
+
*/
|
|
22
|
+
let callbacks;
|
|
23
|
+
let resizeObserver;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Use the single ResizeObserver instance
|
|
27
|
+
* @returns {Object}
|
|
28
|
+
*/
|
|
29
|
+
var resizeObserver$1 = {
|
|
30
|
+
/**
|
|
31
|
+
* @param {jQuery|Element} elem
|
|
32
|
+
* @param {(entry: ResizeObserverEntry, observer: ResizeObserver) => {}} callback
|
|
33
|
+
* @param {Object?} observeOptions - see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#options
|
|
34
|
+
*/
|
|
35
|
+
observe: function (elem) {
|
|
36
|
+
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => {};
|
|
37
|
+
let observeOptions = arguments.length > 2 ? arguments[2] : undefined;
|
|
38
|
+
const node = elem && $(elem).get(0);
|
|
39
|
+
if (!node) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
ensureResizeObserverInstance();
|
|
43
|
+
resizeObserver.observe(node, observeOptions);
|
|
44
|
+
let nodeCallbacks = callbacks.get(node);
|
|
45
|
+
if (!nodeCallbacks) {
|
|
46
|
+
callbacks.set(node, new Set());
|
|
47
|
+
nodeCallbacks = callbacks.get(node);
|
|
48
|
+
}
|
|
49
|
+
nodeCallbacks.add(callback);
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* @param {jQuery|Element} elem
|
|
53
|
+
* @param {Function} callback
|
|
54
|
+
*/
|
|
55
|
+
unobserve: function (elem, callback) {
|
|
56
|
+
const node = elem && $(elem).get(0);
|
|
57
|
+
if (!node) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
ensureResizeObserverInstance();
|
|
61
|
+
const nodeCallbacks = callbacks.get(node);
|
|
62
|
+
if (!nodeCallbacks) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
nodeCallbacks.delete(callback);
|
|
66
|
+
if (nodeCallbacks.size < 1) {
|
|
67
|
+
resizeObserver.unobserve(node);
|
|
68
|
+
callbacks.delete(node);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function ensureResizeObserverInstance() {
|
|
73
|
+
if (!resizeObserver) {
|
|
74
|
+
callbacks = new WeakMap();
|
|
75
|
+
resizeObserver = new ResizeObserver((entries, observer) => {
|
|
76
|
+
for (const entry of entries) {
|
|
77
|
+
const entryCallbacks = callbacks.get(entry.target);
|
|
78
|
+
if (!entryCallbacks) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
for (const entryCallback of entryCallbacks) {
|
|
82
|
+
entryCallback(entry, observer);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return resizeObserver$1;
|
|
90
|
+
|
|
91
|
+
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This program is free software; you can redistribute it and/or
|
|
3
|
+
* modify it under the terms of the GNU General Public License
|
|
4
|
+
* as published by the Free Software Foundation; under version 2
|
|
5
|
+
* of the License (non-upgradable).
|
|
6
|
+
*
|
|
7
|
+
* This program is distributed in the hope that it will be useful,
|
|
8
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10
|
+
* GNU General Public License for more details.
|
|
11
|
+
*
|
|
12
|
+
* You should have received a copy of the GNU General Public License
|
|
13
|
+
* along with this program; if not, write to the Free Software
|
|
14
|
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
15
|
+
*
|
|
16
|
+
* Copyright (c) 2026 (original work) Open Assessment Technologies SA ;
|
|
17
|
+
*/
|
|
18
|
+
import $ from 'jquery';
|
|
19
|
+
|
|
20
|
+
let callbacks;
|
|
21
|
+
let resizeObserver;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Use the single ResizeObserver instance
|
|
25
|
+
* @returns {Object}
|
|
26
|
+
*/
|
|
27
|
+
export default {
|
|
28
|
+
/**
|
|
29
|
+
* @param {jQuery|Element} elem
|
|
30
|
+
* @param {(entry: ResizeObserverEntry, observer: ResizeObserver) => {}} callback
|
|
31
|
+
* @param {Object?} observeOptions - see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#options
|
|
32
|
+
*/
|
|
33
|
+
observe: function (elem, callback = () => {}, observeOptions) {
|
|
34
|
+
const node = elem && $(elem).get(0);
|
|
35
|
+
if (!node) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
ensureResizeObserverInstance();
|
|
40
|
+
resizeObserver.observe(node, observeOptions);
|
|
41
|
+
|
|
42
|
+
let nodeCallbacks = callbacks.get(node);
|
|
43
|
+
if (!nodeCallbacks) {
|
|
44
|
+
callbacks.set(node, new Set());
|
|
45
|
+
nodeCallbacks = callbacks.get(node);
|
|
46
|
+
}
|
|
47
|
+
nodeCallbacks.add(callback);
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {jQuery|Element} elem
|
|
52
|
+
* @param {Function} callback
|
|
53
|
+
*/
|
|
54
|
+
unobserve: function (elem, callback) {
|
|
55
|
+
const node = elem && $(elem).get(0);
|
|
56
|
+
if (!node) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
ensureResizeObserverInstance();
|
|
61
|
+
|
|
62
|
+
const nodeCallbacks = callbacks.get(node);
|
|
63
|
+
if (!nodeCallbacks) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
nodeCallbacks.delete(callback);
|
|
67
|
+
if (nodeCallbacks.size < 1) {
|
|
68
|
+
resizeObserver.unobserve(node);
|
|
69
|
+
callbacks.delete(node);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
function ensureResizeObserverInstance() {
|
|
75
|
+
if (!resizeObserver) {
|
|
76
|
+
callbacks = new WeakMap();
|
|
77
|
+
resizeObserver = new ResizeObserver((entries, observer) => {
|
|
78
|
+
for (const entry of entries) {
|
|
79
|
+
const entryCallbacks = callbacks.get(entry.target);
|
|
80
|
+
if (!entryCallbacks) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
for (const entryCallback of entryCallbacks) {
|
|
84
|
+
entryCallback(entry, observer);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|