@instructure/ui-dom-utils 8.33.1 → 8.33.2-snapshot-5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/es/InputModeListener.js +1 -22
- package/es/addEventListener.js +1 -3
- package/es/addInputModeListener.js +1 -29
- package/es/addPositionChangeListener.js +1 -7
- package/es/addResizeListener.js +1 -8
- package/es/contains.js +2 -8
- package/es/containsActiveElement.js +1 -2
- package/es/elementMatches.js +3 -4
- package/es/findDOMNode.js +4 -11
- package/es/findFocusable.js +1 -12
- package/es/findTabbable.js +1 -3
- package/es/getActiveElement.js +4 -4
- package/es/getBoundingClientRect.js +1 -13
- package/es/getClassList.js +2 -7
- package/es/getComputedStyle.js +1 -5
- package/es/getFontSize.js +5 -8
- package/es/getOffsetParents.js +5 -11
- package/es/getScrollParents.js +8 -20
- package/es/handleMouseOverOut.js +2 -3
- package/es/isActiveElement.js +1 -2
- package/es/isDefinedCustomElement.js +0 -1
- package/es/isVisible.js +11 -18
- package/es/matchMedia.js +1 -4
- package/es/ownerDocument.js +1 -4
- package/es/ownerWindow.js +1 -2
- package/es/requestAnimationFrame.js +2 -5
- package/es/transformSelection.js +4 -10
- package/lib/InputModeListener.js +1 -26
- package/lib/addEventListener.js +0 -4
- package/lib/addInputModeListener.js +1 -32
- package/lib/addPositionChangeListener.js +0 -10
- package/lib/addResizeListener.js +0 -11
- package/lib/canUseDOM.js +0 -1
- package/lib/contains.js +1 -10
- package/lib/containsActiveElement.js +0 -5
- package/lib/elementMatches.js +2 -5
- package/lib/findDOMNode.js +4 -13
- package/lib/findFocusable.js +1 -13
- package/lib/findTabbable.js +1 -4
- package/lib/getActiveElement.js +2 -5
- package/lib/getBoundingClientRect.js +0 -17
- package/lib/getClassList.js +2 -9
- package/lib/getComputedStyle.js +0 -8
- package/lib/getFontSize.js +6 -12
- package/lib/getOffsetParents.js +4 -15
- package/lib/getScrollParents.js +7 -23
- package/lib/handleMouseOverOut.js +0 -4
- package/lib/index.js +0 -26
- package/lib/isActiveElement.js +0 -4
- package/lib/isDefinedCustomElement.js +0 -2
- package/lib/isVisible.js +10 -20
- package/lib/matchMedia.js +0 -7
- package/lib/ownerDocument.js +0 -5
- package/lib/ownerWindow.js +0 -4
- package/lib/requestAnimationFrame.js +1 -6
- package/lib/transformSelection.js +4 -11
- package/package.json +5 -5
- package/tsconfig.build.tsbuildinfo +1 -1
package/lib/getFontSize.js
CHANGED
|
@@ -5,13 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.getFontSize = getFontSize;
|
|
8
|
-
|
|
9
8
|
var _canUseDOM = require("./canUseDOM");
|
|
10
|
-
|
|
11
9
|
var _ownerDocument = require("./ownerDocument");
|
|
12
|
-
|
|
13
10
|
var _getComputedStyle = require("./getComputedStyle");
|
|
14
|
-
|
|
15
11
|
/*
|
|
16
12
|
* The MIT License (MIT)
|
|
17
13
|
*
|
|
@@ -35,7 +31,9 @@ var _getComputedStyle = require("./getComputedStyle");
|
|
|
35
31
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
36
32
|
* SOFTWARE.
|
|
37
33
|
*/
|
|
34
|
+
|
|
38
35
|
const COMPUTED_CACHE = new WeakMap();
|
|
36
|
+
|
|
39
37
|
/**
|
|
40
38
|
* ---
|
|
41
39
|
* category: utilities/DOM
|
|
@@ -48,27 +46,23 @@ const COMPUTED_CACHE = new WeakMap();
|
|
|
48
46
|
* @param { boolean } ignoreCache
|
|
49
47
|
* @returns { number } font size in px
|
|
50
48
|
*/
|
|
51
|
-
|
|
52
49
|
function getFontSize(el) {
|
|
53
50
|
let ignoreCache = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
54
|
-
|
|
55
51
|
if (!_canUseDOM.canUseDOM) {
|
|
56
52
|
return 16;
|
|
57
53
|
}
|
|
54
|
+
const container = el || (0, _ownerDocument.ownerDocument)(el).documentElement;
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
// return the cached font size if it's there
|
|
61
57
|
const cachedValue = COMPUTED_CACHE.get(container);
|
|
62
|
-
|
|
63
58
|
if (!ignoreCache && cachedValue) {
|
|
64
59
|
return cachedValue;
|
|
65
60
|
}
|
|
61
|
+
const fontSize = parseInt((0, _getComputedStyle.getComputedStyle)(container).getPropertyValue('font-size'));
|
|
66
62
|
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
// cache the computed font size so that we don't have to compute it again
|
|
69
64
|
COMPUTED_CACHE.set(container, fontSize);
|
|
70
65
|
return fontSize;
|
|
71
66
|
}
|
|
72
|
-
|
|
73
67
|
var _default = getFontSize;
|
|
74
68
|
exports.default = _default;
|
package/lib/getOffsetParents.js
CHANGED
|
@@ -5,15 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.getOffsetParents = getOffsetParents;
|
|
8
|
-
|
|
9
8
|
var _findDOMNode = require("./findDOMNode");
|
|
10
|
-
|
|
11
9
|
var _canUseDOM = require("./canUseDOM");
|
|
12
|
-
|
|
13
10
|
var _getComputedStyle = require("./getComputedStyle");
|
|
14
|
-
|
|
15
11
|
var _ownerDocument = require("./ownerDocument");
|
|
16
|
-
|
|
17
12
|
/*
|
|
18
13
|
* The MIT License (MIT)
|
|
19
14
|
*
|
|
@@ -53,32 +48,26 @@ var _ownerDocument = require("./ownerDocument");
|
|
|
53
48
|
*/
|
|
54
49
|
function getOffsetParents(el) {
|
|
55
50
|
const parents = [];
|
|
56
|
-
|
|
57
51
|
if (!_canUseDOM.canUseDOM) {
|
|
58
52
|
return parents;
|
|
59
53
|
}
|
|
60
|
-
|
|
61
54
|
const node = el && (0, _findDOMNode.findDOMNode)(el);
|
|
62
|
-
|
|
63
55
|
if (node) {
|
|
64
|
-
let parent = node;
|
|
56
|
+
let parent = node;
|
|
65
57
|
|
|
58
|
+
// eslint-disable-next-line no-cond-assign
|
|
66
59
|
while ((parent = parent.parentNode) && parent && parent.nodeType === 1 && parent.tagName !== 'BODY') {
|
|
67
60
|
const style = (0, _getComputedStyle.getComputedStyle)(parent);
|
|
68
|
-
const transform = style.getPropertyValue('-webkit-transform') || style.getPropertyValue('-moz-transform') || style.getPropertyValue('-ms-transform') || style.getPropertyValue('-o-transform') || style.getPropertyValue('transform') || 'none';
|
|
69
|
-
|
|
61
|
+
const transform = style.getPropertyValue('-webkit-transform') || style.getPropertyValue('-moz-transform') || style.getPropertyValue('-ms-transform') || style.getPropertyValue('-o-transform') || style.getPropertyValue('transform') || 'none';
|
|
62
|
+
// initial value of transform can be 'none' or a matrix equivalent
|
|
70
63
|
const transformDefault = transform === 'none' || transform === 'matrix(1, 0, 0, 1, 0, 0)' ? true : false;
|
|
71
|
-
|
|
72
64
|
if (style.position !== 'static' || !transformDefault) {
|
|
73
65
|
parents.push(parent);
|
|
74
66
|
}
|
|
75
67
|
}
|
|
76
|
-
|
|
77
68
|
parents.push((0, _ownerDocument.ownerDocument)(node).body);
|
|
78
69
|
}
|
|
79
|
-
|
|
80
70
|
return parents;
|
|
81
71
|
}
|
|
82
|
-
|
|
83
72
|
var _default = getOffsetParents;
|
|
84
73
|
exports.default = _default;
|
package/lib/getScrollParents.js
CHANGED
|
@@ -5,13 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.getScrollParents = getScrollParents;
|
|
8
|
-
|
|
9
8
|
var _findDOMNode = require("./findDOMNode");
|
|
10
|
-
|
|
11
9
|
var _canUseDOM = require("./canUseDOM");
|
|
12
|
-
|
|
13
10
|
var _getComputedStyle = require("./getComputedStyle");
|
|
14
|
-
|
|
15
11
|
/*
|
|
16
12
|
* The MIT License (MIT)
|
|
17
13
|
*
|
|
@@ -52,64 +48,52 @@ var _getComputedStyle = require("./getComputedStyle");
|
|
|
52
48
|
*/
|
|
53
49
|
function getScrollParents(el) {
|
|
54
50
|
const parents = [];
|
|
55
|
-
|
|
56
51
|
if (!_canUseDOM.canUseDOM) {
|
|
57
52
|
return parents;
|
|
58
53
|
}
|
|
59
|
-
|
|
60
54
|
const node = el && (0, _findDOMNode.findDOMNode)(el);
|
|
61
|
-
|
|
62
55
|
if (node) {
|
|
63
56
|
// In firefox if the element is inside an iframe with display: none; window.getComputedStyle() will return null;
|
|
64
57
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=548397
|
|
65
58
|
const computedStyle = (0, _getComputedStyle.getComputedStyle)(node) || {};
|
|
66
59
|
const position = computedStyle.position;
|
|
67
|
-
|
|
68
60
|
if (position === 'fixed') {
|
|
69
61
|
return [node.ownerDocument];
|
|
70
62
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
let parent = node;
|
|
64
|
+
// eslint-disable-next-line no-cond-assign
|
|
74
65
|
while (parent && parent.nodeType === 1 && (parent = parent.parentNode)) {
|
|
75
66
|
let style;
|
|
76
|
-
|
|
77
67
|
try {
|
|
78
68
|
style = (0, _getComputedStyle.getComputedStyle)(parent);
|
|
79
69
|
} catch (err) {} // eslint-disable-line no-empty
|
|
80
70
|
|
|
81
|
-
|
|
82
71
|
if (typeof style === 'undefined' || style === null) {
|
|
83
72
|
parents.push(parent);
|
|
84
73
|
return parents;
|
|
85
74
|
}
|
|
86
|
-
|
|
87
75
|
const _ref = style,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
overflow = _ref.overflow,
|
|
77
|
+
overflowX = _ref.overflowX,
|
|
78
|
+
overflowY = _ref.overflowY;
|
|
92
79
|
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
|
|
93
80
|
if (position !== 'absolute' || ['relative', 'absolute', 'fixed'].indexOf(style.position) >= 0) {
|
|
94
81
|
parents.push(parent);
|
|
95
82
|
}
|
|
96
83
|
}
|
|
97
84
|
}
|
|
98
|
-
|
|
99
85
|
const ownerDocument = node.ownerDocument;
|
|
100
|
-
|
|
101
86
|
if (ownerDocument) {
|
|
102
|
-
parents.push(ownerDocument.body);
|
|
87
|
+
parents.push(ownerDocument.body);
|
|
103
88
|
|
|
89
|
+
// If the node is within a frame, account for the parent window scroll
|
|
104
90
|
if (ownerDocument !== document) {
|
|
105
91
|
// ownerDocument.defaultView can be null
|
|
106
92
|
parents.push(ownerDocument.defaultView);
|
|
107
93
|
}
|
|
108
94
|
}
|
|
109
95
|
}
|
|
110
|
-
|
|
111
96
|
return parents;
|
|
112
97
|
}
|
|
113
|
-
|
|
114
98
|
var _default = getScrollParents;
|
|
115
99
|
exports.default = _default;
|
|
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.handleMouseOverOut = handleMouseOverOut;
|
|
8
|
-
|
|
9
8
|
var _contains = require("./contains");
|
|
10
|
-
|
|
11
9
|
/*
|
|
12
10
|
* The MIT License (MIT)
|
|
13
11
|
*
|
|
@@ -49,11 +47,9 @@ var _contains = require("./contains");
|
|
|
49
47
|
function handleMouseOverOut(handler, event) {
|
|
50
48
|
const target = event.currentTarget;
|
|
51
49
|
const related = event.relatedTarget;
|
|
52
|
-
|
|
53
50
|
if (!related || related !== target && !(0, _contains.contains)(target, related)) {
|
|
54
51
|
handler(event);
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
|
-
|
|
58
54
|
var _default = handleMouseOverOut;
|
|
59
55
|
exports.default = _default;
|
package/lib/index.js
CHANGED
|
@@ -159,55 +159,29 @@ Object.defineProperty(exports, "transformSelection", {
|
|
|
159
159
|
return _transformSelection.transformSelection;
|
|
160
160
|
}
|
|
161
161
|
});
|
|
162
|
-
|
|
163
162
|
var _addEventListener = require("./addEventListener");
|
|
164
|
-
|
|
165
163
|
var _addInputModeListener = require("./addInputModeListener");
|
|
166
|
-
|
|
167
164
|
var _addPositionChangeListener = require("./addPositionChangeListener");
|
|
168
|
-
|
|
169
165
|
var _addResizeListener = require("./addResizeListener");
|
|
170
|
-
|
|
171
166
|
var _canUseDOM = require("./canUseDOM");
|
|
172
|
-
|
|
173
167
|
var _contains = require("./contains");
|
|
174
|
-
|
|
175
168
|
var _containsActiveElement = require("./containsActiveElement");
|
|
176
|
-
|
|
177
169
|
var _elementMatches = require("./elementMatches");
|
|
178
|
-
|
|
179
170
|
var _findDOMNode = require("./findDOMNode");
|
|
180
|
-
|
|
181
171
|
var _findFocusable = require("./findFocusable");
|
|
182
|
-
|
|
183
172
|
var _findTabbable = require("./findTabbable");
|
|
184
|
-
|
|
185
173
|
var _getActiveElement = require("./getActiveElement");
|
|
186
|
-
|
|
187
174
|
var _getBoundingClientRect = require("./getBoundingClientRect");
|
|
188
|
-
|
|
189
175
|
var _getClassList = require("./getClassList");
|
|
190
|
-
|
|
191
176
|
var _getComputedStyle = require("./getComputedStyle");
|
|
192
|
-
|
|
193
177
|
var _getFontSize = require("./getFontSize");
|
|
194
|
-
|
|
195
178
|
var _getOffsetParents = require("./getOffsetParents");
|
|
196
|
-
|
|
197
179
|
var _getScrollParents = require("./getScrollParents");
|
|
198
|
-
|
|
199
180
|
var _handleMouseOverOut = require("./handleMouseOverOut");
|
|
200
|
-
|
|
201
181
|
var _isActiveElement = require("./isActiveElement");
|
|
202
|
-
|
|
203
182
|
var _isVisible = require("./isVisible");
|
|
204
|
-
|
|
205
183
|
var _ownerDocument = require("./ownerDocument");
|
|
206
|
-
|
|
207
184
|
var _ownerWindow = require("./ownerWindow");
|
|
208
|
-
|
|
209
185
|
var _requestAnimationFrame = require("./requestAnimationFrame");
|
|
210
|
-
|
|
211
186
|
var _transformSelection = require("./transformSelection");
|
|
212
|
-
|
|
213
187
|
var _matchMedia = require("./matchMedia");
|
package/lib/isActiveElement.js
CHANGED
|
@@ -5,11 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.isActiveElement = isActiveElement;
|
|
8
|
-
|
|
9
8
|
var _findDOMNode = require("./findDOMNode");
|
|
10
|
-
|
|
11
9
|
var _getActiveElement = require("./getActiveElement");
|
|
12
|
-
|
|
13
10
|
/*
|
|
14
11
|
* The MIT License (MIT)
|
|
15
12
|
*
|
|
@@ -48,6 +45,5 @@ function isActiveElement(el) {
|
|
|
48
45
|
const node = el && (0, _findDOMNode.findDOMNode)(el);
|
|
49
46
|
return node ? (0, _getActiveElement.getActiveElement)() === node : false;
|
|
50
47
|
}
|
|
51
|
-
|
|
52
48
|
var _default = isActiveElement;
|
|
53
49
|
exports.default = _default;
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.isDefinedCustomElement = isDefinedCustomElement;
|
|
8
|
-
|
|
9
8
|
/*
|
|
10
9
|
* The MIT License (MIT)
|
|
11
10
|
*
|
|
@@ -43,6 +42,5 @@ exports.isDefinedCustomElement = isDefinedCustomElement;
|
|
|
43
42
|
function isDefinedCustomElement(el) {
|
|
44
43
|
return Boolean(el.tagName.includes('-') && customElements.get(el.tagName.toLowerCase()));
|
|
45
44
|
}
|
|
46
|
-
|
|
47
45
|
var _default = isDefinedCustomElement;
|
|
48
46
|
exports.default = _default;
|
package/lib/isVisible.js
CHANGED
|
@@ -5,11 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.isVisible = isVisible;
|
|
8
|
-
|
|
9
8
|
var _findDOMNode = require("./findDOMNode");
|
|
10
|
-
|
|
11
9
|
var _getComputedStyle = require("./getComputedStyle");
|
|
12
|
-
|
|
13
10
|
/*
|
|
14
11
|
* The MIT License (MIT)
|
|
15
12
|
*
|
|
@@ -50,30 +47,26 @@ var _getComputedStyle = require("./getComputedStyle");
|
|
|
50
47
|
*/
|
|
51
48
|
function isVisible(el) {
|
|
52
49
|
let recursive = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
|
|
53
|
-
const node = el && (0, _findDOMNode.findDOMNode)(el);
|
|
54
|
-
|
|
50
|
+
const node = el && (0, _findDOMNode.findDOMNode)(el);
|
|
51
|
+
// skip document or window nodes
|
|
55
52
|
if (node === window || node === document || node === document.body) {
|
|
56
53
|
return true;
|
|
57
54
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
const parent = node.parentNode;
|
|
56
|
+
// skip text node, check parent
|
|
61
57
|
if (node.nodeType === 3) {
|
|
62
58
|
return isVisible(parent, recursive);
|
|
63
59
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
const style = node ? (0, _getComputedStyle.getComputedStyle)(node) : {};
|
|
61
|
+
// physically and visually hidden
|
|
67
62
|
if (style.display === 'none') {
|
|
68
63
|
return false;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
}
|
|
65
|
+
// visually hidden
|
|
72
66
|
if (style.visibility === 'hidden' || style.opacity === '0') {
|
|
73
67
|
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
}
|
|
69
|
+
// hidden by clipping
|
|
77
70
|
if (style.overflow === 'hidden' && style.position === 'absolute' && style.clip !== 'auto') {
|
|
78
71
|
const rect = style.clip.substring(5).slice(0, -1).split(', ');
|
|
79
72
|
let zeros = true;
|
|
@@ -82,12 +75,10 @@ function isVisible(el) {
|
|
|
82
75
|
zeros = false;
|
|
83
76
|
}
|
|
84
77
|
});
|
|
85
|
-
|
|
86
78
|
if (zeros) {
|
|
87
79
|
return false;
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
|
-
|
|
91
82
|
if (recursive && parent) {
|
|
92
83
|
// recursively check parent visibility
|
|
93
84
|
return isVisible(parent);
|
|
@@ -95,6 +86,5 @@ function isVisible(el) {
|
|
|
95
86
|
return true;
|
|
96
87
|
}
|
|
97
88
|
}
|
|
98
|
-
|
|
99
89
|
var _default = isVisible;
|
|
100
90
|
exports.default = _default;
|
package/lib/matchMedia.js
CHANGED
|
@@ -5,13 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.matchMedia = matchMedia;
|
|
8
|
-
|
|
9
8
|
var _canUseDOM = require("./canUseDOM");
|
|
10
|
-
|
|
11
9
|
var _findDOMNode = require("./findDOMNode");
|
|
12
|
-
|
|
13
10
|
var _ownerWindow = require("./ownerWindow");
|
|
14
|
-
|
|
15
11
|
/*
|
|
16
12
|
* The MIT License (MIT)
|
|
17
13
|
*
|
|
@@ -51,14 +47,11 @@ var _ownerWindow = require("./ownerWindow");
|
|
|
51
47
|
*/
|
|
52
48
|
function matchMedia(query, el) {
|
|
53
49
|
const node = (0, _findDOMNode.findDOMNode)(el) || document;
|
|
54
|
-
|
|
55
50
|
if (_canUseDOM.canUseDOM) {
|
|
56
51
|
const window = (0, _ownerWindow.ownerWindow)(node);
|
|
57
52
|
return window && window.matchMedia(query);
|
|
58
53
|
}
|
|
59
|
-
|
|
60
54
|
return null;
|
|
61
55
|
}
|
|
62
|
-
|
|
63
56
|
var _default = matchMedia;
|
|
64
57
|
exports.default = _default;
|
package/lib/ownerDocument.js
CHANGED
|
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.ownerDocument = ownerDocument;
|
|
8
|
-
|
|
9
8
|
var _findDOMNode = require("./findDOMNode");
|
|
10
|
-
|
|
11
9
|
/*
|
|
12
10
|
* The MIT License (MIT)
|
|
13
11
|
*
|
|
@@ -45,13 +43,10 @@ var _findDOMNode = require("./findDOMNode");
|
|
|
45
43
|
function ownerDocument(el) {
|
|
46
44
|
const node = el && (0, _findDOMNode.findDOMNode)(el);
|
|
47
45
|
let ownerDocument;
|
|
48
|
-
|
|
49
46
|
if (node && 'ownerDocument' in node) {
|
|
50
47
|
ownerDocument = node.ownerDocument;
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
return ownerDocument || document;
|
|
54
50
|
}
|
|
55
|
-
|
|
56
51
|
var _default = ownerDocument;
|
|
57
52
|
exports.default = _default;
|
package/lib/ownerWindow.js
CHANGED
|
@@ -5,11 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.ownerWindow = ownerWindow;
|
|
8
|
-
|
|
9
8
|
var _findDOMNode = require("./findDOMNode");
|
|
10
|
-
|
|
11
9
|
var _ownerDocument = require("./ownerDocument");
|
|
12
|
-
|
|
13
10
|
/*
|
|
14
11
|
* The MIT License (MIT)
|
|
15
12
|
*
|
|
@@ -49,6 +46,5 @@ function ownerWindow(el) {
|
|
|
49
46
|
const doc = (0, _ownerDocument.ownerDocument)(node);
|
|
50
47
|
return doc && doc.defaultView;
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
var _default = ownerWindow;
|
|
54
50
|
exports.default = _default;
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.requestAnimationFrame = exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _canUseDOM = require("./canUseDOM");
|
|
9
|
-
|
|
10
8
|
/*
|
|
11
9
|
* The MIT License (MIT)
|
|
12
10
|
*
|
|
@@ -45,8 +43,8 @@ var _canUseDOM = require("./canUseDOM");
|
|
|
45
43
|
*/
|
|
46
44
|
const requestAnimationFrame = function () {
|
|
47
45
|
let requestAnimationFrame;
|
|
48
|
-
/* istanbul ignore else */
|
|
49
46
|
|
|
47
|
+
/* istanbul ignore else */
|
|
50
48
|
if (_canUseDOM.canUseDOM && window.requestAnimationFrame && window.cancelAnimationFrame) {
|
|
51
49
|
requestAnimationFrame = cb => {
|
|
52
50
|
const id = window.requestAnimationFrame(cb);
|
|
@@ -57,7 +55,6 @@ const requestAnimationFrame = function () {
|
|
|
57
55
|
} else {
|
|
58
56
|
/* https://github.com/component/raf */
|
|
59
57
|
let prev = new Date().getTime();
|
|
60
|
-
|
|
61
58
|
requestAnimationFrame = cb => {
|
|
62
59
|
const curr = new Date().getTime();
|
|
63
60
|
const ms = Math.max(0, 16 - (curr - prev));
|
|
@@ -68,10 +65,8 @@ const requestAnimationFrame = function () {
|
|
|
68
65
|
};
|
|
69
66
|
};
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
return requestAnimationFrame;
|
|
73
69
|
}();
|
|
74
|
-
|
|
75
70
|
exports.requestAnimationFrame = requestAnimationFrame;
|
|
76
71
|
var _default = requestAnimationFrame;
|
|
77
72
|
exports.default = _default;
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.transformCursor = transformCursor;
|
|
8
8
|
exports.transformSelection = transformSelection;
|
|
9
|
-
|
|
10
9
|
/*
|
|
11
10
|
* The MIT License (MIT)
|
|
12
11
|
*
|
|
@@ -45,15 +44,16 @@ exports.transformSelection = transformSelection;
|
|
|
45
44
|
*/
|
|
46
45
|
function transformSelection(element, cleanedValue) {
|
|
47
46
|
const selectionStart = element.selectionStart,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
selectionEnd = element.selectionEnd,
|
|
48
|
+
selectionDirection = element.selectionDirection,
|
|
49
|
+
value = element.value;
|
|
51
50
|
return {
|
|
52
51
|
selectionStart: transformCursor(selectionStart, value, cleanedValue),
|
|
53
52
|
selectionEnd: transformCursor(selectionEnd, value, cleanedValue),
|
|
54
53
|
selectionDirection
|
|
55
54
|
};
|
|
56
55
|
}
|
|
56
|
+
|
|
57
57
|
/**
|
|
58
58
|
* Calculate the resulting cursor position
|
|
59
59
|
* within a string when some characters are removed
|
|
@@ -63,29 +63,22 @@ function transformSelection(element, cleanedValue) {
|
|
|
63
63
|
* @param {string} cleanedValue - original string with some characters removed
|
|
64
64
|
* @returns {number} resulting cursor index
|
|
65
65
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
66
|
function transformCursor(cursorIndex, dirtyValue, cleanedValue) {
|
|
69
67
|
if (dirtyValue.length === cleanedValue.length) {
|
|
70
68
|
return cursorIndex;
|
|
71
69
|
}
|
|
72
|
-
|
|
73
70
|
if (cursorIndex === 0) {
|
|
74
71
|
return 0;
|
|
75
72
|
}
|
|
76
|
-
|
|
77
73
|
if (cursorIndex === dirtyValue.length) {
|
|
78
74
|
return cleanedValue.length;
|
|
79
75
|
}
|
|
80
|
-
|
|
81
76
|
return dirtyValue.split('').slice(0, cursorIndex).reduce((result, value) => {
|
|
82
77
|
if (value === cleanedValue[result]) {
|
|
83
78
|
return result + 1;
|
|
84
79
|
}
|
|
85
|
-
|
|
86
80
|
return result;
|
|
87
81
|
}, 0);
|
|
88
82
|
}
|
|
89
|
-
|
|
90
83
|
var _default = transformSelection;
|
|
91
84
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-dom-utils",
|
|
3
|
-
"version": "8.33.
|
|
3
|
+
"version": "8.33.2-snapshot-5",
|
|
4
4
|
"description": "A DOM utility library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@instructure/ui-babel-preset": "8.33.
|
|
26
|
-
"@instructure/ui-test-utils": "8.33.
|
|
25
|
+
"@instructure/ui-babel-preset": "8.33.2-snapshot-5",
|
|
26
|
+
"@instructure/ui-test-utils": "8.33.2-snapshot-5"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/runtime": "^7.13.10",
|
|
30
|
-
"@instructure/console": "8.33.
|
|
31
|
-
"@instructure/shared-types": "8.33.
|
|
30
|
+
"@instructure/console": "8.33.2-snapshot-5",
|
|
31
|
+
"@instructure/shared-types": "8.33.2-snapshot-5"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"react": ">=16.8 <=18",
|