@rc-component/util 1.0.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/LICENSE +22 -0
- package/README.md +303 -0
- package/es/Children/toArray.d.ts +5 -0
- package/es/Children/toArray.js +19 -0
- package/es/Dom/canUseDom.d.ts +1 -0
- package/es/Dom/canUseDom.js +3 -0
- package/es/Dom/contains.d.ts +1 -0
- package/es/Dom/contains.js +20 -0
- package/es/Dom/dynamicCSS.d.ts +25 -0
- package/es/Dom/dynamicCSS.js +153 -0
- package/es/Dom/findDOMNode.d.ts +12 -0
- package/es/Dom/findDOMNode.js +36 -0
- package/es/Dom/focus.d.ts +8 -0
- package/es/Dom/focus.js +87 -0
- package/es/Dom/isVisible.d.ts +2 -0
- package/es/Dom/isVisible.js +27 -0
- package/es/Dom/scrollLocker.d.ts +12 -0
- package/es/Dom/scrollLocker.js +135 -0
- package/es/Dom/shadow.d.ts +8 -0
- package/es/Dom/shadow.js +18 -0
- package/es/Dom/styleChecker.d.ts +2 -0
- package/es/Dom/styleChecker.js +26 -0
- package/es/KeyCode.d.ts +436 -0
- package/es/KeyCode.js +538 -0
- package/es/Portal.d.ts +9 -0
- package/es/Portal.js +44 -0
- package/es/PortalWrapper.d.ts +51 -0
- package/es/PortalWrapper.js +217 -0
- package/es/React/isFragment.d.ts +4 -0
- package/es/React/isFragment.js +18 -0
- package/es/React/render.d.ts +13 -0
- package/es/React/render.js +114 -0
- package/es/composeProps.d.ts +2 -0
- package/es/composeProps.js +24 -0
- package/es/getScrollBarSize.d.ts +7 -0
- package/es/getScrollBarSize.js +76 -0
- package/es/hooks/useEffect.d.ts +2 -0
- package/es/hooks/useEffect.js +14 -0
- package/es/hooks/useEvent.d.ts +2 -0
- package/es/hooks/useEvent.js +16 -0
- package/es/hooks/useId.d.ts +4 -0
- package/es/hooks/useId.js +69 -0
- package/es/hooks/useLayoutEffect.d.ts +4 -0
- package/es/hooks/useLayoutEffect.js +30 -0
- package/es/hooks/useMemo.d.ts +1 -0
- package/es/hooks/useMemo.js +9 -0
- package/es/hooks/useMergedState.d.ts +12 -0
- package/es/hooks/useMergedState.js +68 -0
- package/es/hooks/useMobile.d.ts +6 -0
- package/es/hooks/useMobile.js +25 -0
- package/es/hooks/useState.d.ts +14 -0
- package/es/hooks/useState.js +32 -0
- package/es/hooks/useSyncState.d.ts +9 -0
- package/es/hooks/useSyncState.js +29 -0
- package/es/index.d.ts +6 -0
- package/es/index.js +6 -0
- package/es/isEqual.d.ts +9 -0
- package/es/isEqual.js +55 -0
- package/es/isMobile.d.ts +2 -0
- package/es/isMobile.js +7 -0
- package/es/omit.d.ts +1 -0
- package/es/omit.js +9 -0
- package/es/pickAttrs.d.ts +11 -0
- package/es/pickAttrs.js +51 -0
- package/es/proxyObject.d.ts +4 -0
- package/es/proxyObject.js +19 -0
- package/es/raf.d.ts +6 -0
- package/es/raf.js +54 -0
- package/es/ref.d.ts +19 -0
- package/es/ref.js +89 -0
- package/es/setStyle.d.ts +12 -0
- package/es/setStyle.js +26 -0
- package/es/test/domHook.d.ts +8 -0
- package/es/test/domHook.js +64 -0
- package/es/utils/get.d.ts +1 -0
- package/es/utils/get.js +10 -0
- package/es/utils/set.d.ts +6 -0
- package/es/utils/set.js +93 -0
- package/es/warning.d.ts +32 -0
- package/es/warning.js +68 -0
- package/lib/Children/toArray.d.ts +5 -0
- package/lib/Children/toArray.js +26 -0
- package/lib/Dom/canUseDom.d.ts +1 -0
- package/lib/Dom/canUseDom.js +9 -0
- package/lib/Dom/contains.d.ts +1 -0
- package/lib/Dom/contains.js +26 -0
- package/lib/Dom/dynamicCSS.d.ts +25 -0
- package/lib/Dom/dynamicCSS.js +163 -0
- package/lib/Dom/findDOMNode.d.ts +12 -0
- package/lib/Dom/findDOMNode.js +45 -0
- package/lib/Dom/focus.d.ts +8 -0
- package/lib/Dom/focus.js +98 -0
- package/lib/Dom/isVisible.d.ts +2 -0
- package/lib/Dom/isVisible.js +33 -0
- package/lib/Dom/scrollLocker.d.ts +12 -0
- package/lib/Dom/scrollLocker.js +141 -0
- package/lib/Dom/shadow.d.ts +8 -0
- package/lib/Dom/shadow.js +25 -0
- package/lib/Dom/styleChecker.d.ts +2 -0
- package/lib/Dom/styleChecker.js +33 -0
- package/lib/KeyCode.d.ts +436 -0
- package/lib/KeyCode.js +544 -0
- package/lib/Portal.d.ts +9 -0
- package/lib/Portal.js +51 -0
- package/lib/PortalWrapper.d.ts +51 -0
- package/lib/PortalWrapper.js +226 -0
- package/lib/React/isFragment.d.ts +4 -0
- package/lib/React/isFragment.js +24 -0
- package/lib/React/render.d.ts +13 -0
- package/lib/React/render.js +125 -0
- package/lib/composeProps.d.ts +2 -0
- package/lib/composeProps.js +30 -0
- package/lib/getScrollBarSize.d.ts +7 -0
- package/lib/getScrollBarSize.js +84 -0
- package/lib/hooks/useEffect.d.ts +2 -0
- package/lib/hooks/useEffect.js +22 -0
- package/lib/hooks/useEvent.d.ts +2 -0
- package/lib/hooks/useEvent.js +26 -0
- package/lib/hooks/useId.d.ts +4 -0
- package/lib/hooks/useId.js +78 -0
- package/lib/hooks/useLayoutEffect.d.ts +4 -0
- package/lib/hooks/useLayoutEffect.js +39 -0
- package/lib/hooks/useMemo.d.ts +1 -0
- package/lib/hooks/useMemo.js +18 -0
- package/lib/hooks/useMergedState.d.ts +12 -0
- package/lib/hooks/useMergedState.js +75 -0
- package/lib/hooks/useMobile.d.ts +6 -0
- package/lib/hooks/useMobile.js +31 -0
- package/lib/hooks/useState.d.ts +14 -0
- package/lib/hooks/useState.js +41 -0
- package/lib/hooks/useSyncState.d.ts +9 -0
- package/lib/hooks/useSyncState.js +39 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +60 -0
- package/lib/isEqual.d.ts +9 -0
- package/lib/isEqual.js +61 -0
- package/lib/isMobile.d.ts +2 -0
- package/lib/isMobile.js +13 -0
- package/lib/omit.d.ts +1 -0
- package/lib/omit.js +15 -0
- package/lib/pickAttrs.d.ts +11 -0
- package/lib/pickAttrs.js +57 -0
- package/lib/proxyObject.d.ts +4 -0
- package/lib/proxyObject.js +25 -0
- package/lib/raf.d.ts +6 -0
- package/lib/raf.js +60 -0
- package/lib/ref.d.ts +19 -0
- package/lib/ref.js +96 -0
- package/lib/setStyle.d.ts +12 -0
- package/lib/setStyle.js +32 -0
- package/lib/test/domHook.d.ts +8 -0
- package/lib/test/domHook.js +71 -0
- package/lib/utils/get.d.ts +1 -0
- package/lib/utils/get.js +16 -0
- package/lib/utils/set.d.ts +6 -0
- package/lib/utils/set.js +101 -0
- package/lib/warning.d.ts +32 -0
- package/lib/warning.js +81 -0
- package/package.json +76 -0
package/es/Dom/focus.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
import isVisible from "./isVisible";
|
|
8
|
+
function focusable(node) {
|
|
9
|
+
var includePositive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
10
|
+
if (isVisible(node)) {
|
|
11
|
+
var nodeName = node.nodeName.toLowerCase();
|
|
12
|
+
var isFocusableElement =
|
|
13
|
+
// Focusable element
|
|
14
|
+
['input', 'select', 'textarea', 'button'].includes(nodeName) ||
|
|
15
|
+
// Editable element
|
|
16
|
+
node.isContentEditable ||
|
|
17
|
+
// Anchor with href element
|
|
18
|
+
nodeName === 'a' && !!node.getAttribute('href');
|
|
19
|
+
|
|
20
|
+
// Get tabIndex
|
|
21
|
+
var tabIndexAttr = node.getAttribute('tabindex');
|
|
22
|
+
var tabIndexNum = Number(tabIndexAttr);
|
|
23
|
+
|
|
24
|
+
// Parse as number if validate
|
|
25
|
+
var tabIndex = null;
|
|
26
|
+
if (tabIndexAttr && !Number.isNaN(tabIndexNum)) {
|
|
27
|
+
tabIndex = tabIndexNum;
|
|
28
|
+
} else if (isFocusableElement && tabIndex === null) {
|
|
29
|
+
tabIndex = 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Block focusable if disabled
|
|
33
|
+
if (isFocusableElement && node.disabled) {
|
|
34
|
+
tabIndex = null;
|
|
35
|
+
}
|
|
36
|
+
return tabIndex !== null && (tabIndex >= 0 || includePositive && tabIndex < 0);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
export function getFocusNodeList(node) {
|
|
41
|
+
var includePositive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
42
|
+
var res = _toConsumableArray(node.querySelectorAll('*')).filter(function (child) {
|
|
43
|
+
return focusable(child, includePositive);
|
|
44
|
+
});
|
|
45
|
+
if (focusable(node, includePositive)) {
|
|
46
|
+
res.unshift(node);
|
|
47
|
+
}
|
|
48
|
+
return res;
|
|
49
|
+
}
|
|
50
|
+
var lastFocusElement = null;
|
|
51
|
+
|
|
52
|
+
/** @deprecated Do not use since this may failed when used in async */
|
|
53
|
+
export function saveLastFocusNode() {
|
|
54
|
+
lastFocusElement = document.activeElement;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @deprecated Do not use since this may failed when used in async */
|
|
58
|
+
export function clearLastFocusNode() {
|
|
59
|
+
lastFocusElement = null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @deprecated Do not use since this may failed when used in async */
|
|
63
|
+
export function backLastFocusNode() {
|
|
64
|
+
if (lastFocusElement) {
|
|
65
|
+
try {
|
|
66
|
+
// 元素可能已经被移动了
|
|
67
|
+
lastFocusElement.focus();
|
|
68
|
+
|
|
69
|
+
/* eslint-disable no-empty */
|
|
70
|
+
} catch (e) {
|
|
71
|
+
// empty
|
|
72
|
+
}
|
|
73
|
+
/* eslint-enable no-empty */
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function limitTabRange(node, e) {
|
|
77
|
+
if (e.keyCode === 9) {
|
|
78
|
+
var tabNodeList = getFocusNodeList(node);
|
|
79
|
+
var lastTabNode = tabNodeList[e.shiftKey ? 0 : tabNodeList.length - 1];
|
|
80
|
+
var leavingTab = lastTabNode === document.activeElement || node === document.activeElement;
|
|
81
|
+
if (leavingTab) {
|
|
82
|
+
var target = tabNodeList[e.shiftKey ? tabNodeList.length - 1 : 0];
|
|
83
|
+
target.focus();
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default (function (element) {
|
|
2
|
+
if (!element) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
if (element instanceof Element) {
|
|
6
|
+
if (element.offsetParent) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (element.getBBox) {
|
|
10
|
+
var _getBBox = element.getBBox(),
|
|
11
|
+
width = _getBBox.width,
|
|
12
|
+
height = _getBBox.height;
|
|
13
|
+
if (width || height) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (element.getBoundingClientRect) {
|
|
18
|
+
var _element$getBoundingC = element.getBoundingClientRect(),
|
|
19
|
+
_width = _element$getBoundingC.width,
|
|
20
|
+
_height = _element$getBoundingC.height;
|
|
21
|
+
if (_width || _height) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface scrollLockOptions {
|
|
2
|
+
container: HTMLElement;
|
|
3
|
+
}
|
|
4
|
+
export default class ScrollLocker {
|
|
5
|
+
private lockTarget;
|
|
6
|
+
private options;
|
|
7
|
+
constructor(options?: scrollLockOptions);
|
|
8
|
+
getContainer: () => HTMLElement | undefined;
|
|
9
|
+
reLock: (options?: scrollLockOptions) => void;
|
|
10
|
+
lock: () => void;
|
|
11
|
+
unLock: () => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
13
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
|
+
import getScrollBarSize from "../getScrollBarSize";
|
|
15
|
+
import setStyle from "../setStyle";
|
|
16
|
+
var uuid = 0;
|
|
17
|
+
var locks = [];
|
|
18
|
+
var scrollingEffectClassName = 'ant-scrolling-effect';
|
|
19
|
+
var scrollingEffectClassNameReg = new RegExp("".concat(scrollingEffectClassName), 'g');
|
|
20
|
+
|
|
21
|
+
// https://github.com/ant-design/ant-design/issues/19340
|
|
22
|
+
// https://github.com/ant-design/ant-design/issues/19332
|
|
23
|
+
var cacheStyle = new Map();
|
|
24
|
+
var ScrollLocker = /*#__PURE__*/_createClass(function ScrollLocker(_options) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
_classCallCheck(this, ScrollLocker);
|
|
27
|
+
_defineProperty(this, "lockTarget", void 0);
|
|
28
|
+
_defineProperty(this, "options", void 0);
|
|
29
|
+
_defineProperty(this, "getContainer", function () {
|
|
30
|
+
var _this$options;
|
|
31
|
+
return (_this$options = _this.options) === null || _this$options === void 0 ? void 0 : _this$options.container;
|
|
32
|
+
});
|
|
33
|
+
// if options change...
|
|
34
|
+
_defineProperty(this, "reLock", function (options) {
|
|
35
|
+
var findLock = locks.find(function (_ref) {
|
|
36
|
+
var target = _ref.target;
|
|
37
|
+
return target === _this.lockTarget;
|
|
38
|
+
});
|
|
39
|
+
if (findLock) {
|
|
40
|
+
_this.unLock();
|
|
41
|
+
}
|
|
42
|
+
_this.options = options;
|
|
43
|
+
if (findLock) {
|
|
44
|
+
findLock.options = options;
|
|
45
|
+
_this.lock();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
_defineProperty(this, "lock", function () {
|
|
49
|
+
var _this$options3;
|
|
50
|
+
// If lockTarget exist return
|
|
51
|
+
if (locks.some(function (_ref2) {
|
|
52
|
+
var target = _ref2.target;
|
|
53
|
+
return target === _this.lockTarget;
|
|
54
|
+
})) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// If same container effect, return
|
|
59
|
+
if (locks.some(function (_ref3) {
|
|
60
|
+
var _this$options2;
|
|
61
|
+
var options = _ref3.options;
|
|
62
|
+
return (options === null || options === void 0 ? void 0 : options.container) === ((_this$options2 = _this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.container);
|
|
63
|
+
})) {
|
|
64
|
+
locks = [].concat(_toConsumableArray(locks), [{
|
|
65
|
+
target: _this.lockTarget,
|
|
66
|
+
options: _this.options
|
|
67
|
+
}]);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
var scrollBarSize = 0;
|
|
71
|
+
var container = ((_this$options3 = _this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.container) || document.body;
|
|
72
|
+
if (container === document.body && window.innerWidth - document.documentElement.clientWidth > 0 || container.scrollHeight > container.clientHeight) {
|
|
73
|
+
if (getComputedStyle(container).overflow !== 'hidden') {
|
|
74
|
+
scrollBarSize = getScrollBarSize();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
var containerClassName = container.className;
|
|
78
|
+
if (locks.filter(function (_ref4) {
|
|
79
|
+
var _this$options4;
|
|
80
|
+
var options = _ref4.options;
|
|
81
|
+
return (options === null || options === void 0 ? void 0 : options.container) === ((_this$options4 = _this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.container);
|
|
82
|
+
}).length === 0) {
|
|
83
|
+
cacheStyle.set(container, setStyle({
|
|
84
|
+
width: scrollBarSize !== 0 ? "calc(100% - ".concat(scrollBarSize, "px)") : undefined,
|
|
85
|
+
overflow: 'hidden',
|
|
86
|
+
overflowX: 'hidden',
|
|
87
|
+
overflowY: 'hidden'
|
|
88
|
+
}, {
|
|
89
|
+
element: container
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// https://github.com/ant-design/ant-design/issues/19729
|
|
94
|
+
if (!scrollingEffectClassNameReg.test(containerClassName)) {
|
|
95
|
+
var addClassName = "".concat(containerClassName, " ").concat(scrollingEffectClassName);
|
|
96
|
+
container.className = addClassName.trim();
|
|
97
|
+
}
|
|
98
|
+
locks = [].concat(_toConsumableArray(locks), [{
|
|
99
|
+
target: _this.lockTarget,
|
|
100
|
+
options: _this.options
|
|
101
|
+
}]);
|
|
102
|
+
});
|
|
103
|
+
_defineProperty(this, "unLock", function () {
|
|
104
|
+
var _this$options5;
|
|
105
|
+
var findLock = locks.find(function (_ref5) {
|
|
106
|
+
var target = _ref5.target;
|
|
107
|
+
return target === _this.lockTarget;
|
|
108
|
+
});
|
|
109
|
+
locks = locks.filter(function (_ref6) {
|
|
110
|
+
var target = _ref6.target;
|
|
111
|
+
return target !== _this.lockTarget;
|
|
112
|
+
});
|
|
113
|
+
if (!findLock || locks.some(function (_ref7) {
|
|
114
|
+
var _findLock$options;
|
|
115
|
+
var options = _ref7.options;
|
|
116
|
+
return (options === null || options === void 0 ? void 0 : options.container) === ((_findLock$options = findLock.options) === null || _findLock$options === void 0 ? void 0 : _findLock$options.container);
|
|
117
|
+
})) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Remove Effect
|
|
122
|
+
var container = ((_this$options5 = _this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.container) || document.body;
|
|
123
|
+
var containerClassName = container.className;
|
|
124
|
+
if (!scrollingEffectClassNameReg.test(containerClassName)) return;
|
|
125
|
+
setStyle(cacheStyle.get(container), {
|
|
126
|
+
element: container
|
|
127
|
+
});
|
|
128
|
+
cacheStyle.delete(container);
|
|
129
|
+
container.className = container.className.replace(scrollingEffectClassNameReg, '').trim();
|
|
130
|
+
});
|
|
131
|
+
// eslint-disable-next-line no-plusplus
|
|
132
|
+
this.lockTarget = uuid++;
|
|
133
|
+
this.options = _options;
|
|
134
|
+
});
|
|
135
|
+
export { ScrollLocker as default };
|
package/es/Dom/shadow.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function getRoot(ele) {
|
|
2
|
+
var _ele$getRootNode;
|
|
3
|
+
return ele === null || ele === void 0 || (_ele$getRootNode = ele.getRootNode) === null || _ele$getRootNode === void 0 ? void 0 : _ele$getRootNode.call(ele);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Check if is in shadowRoot
|
|
8
|
+
*/
|
|
9
|
+
export function inShadow(ele) {
|
|
10
|
+
return getRoot(ele) instanceof ShadowRoot;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Return shadowRoot if possible
|
|
15
|
+
*/
|
|
16
|
+
export function getShadowRoot(ele) {
|
|
17
|
+
return inShadow(ele) ? getRoot(ele) : null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import canUseDom from "./canUseDom";
|
|
2
|
+
var isStyleNameSupport = function isStyleNameSupport(styleName) {
|
|
3
|
+
if (canUseDom() && window.document.documentElement) {
|
|
4
|
+
var styleNameList = Array.isArray(styleName) ? styleName : [styleName];
|
|
5
|
+
var documentElement = window.document.documentElement;
|
|
6
|
+
return styleNameList.some(function (name) {
|
|
7
|
+
return name in documentElement.style;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
};
|
|
12
|
+
var isStyleValueSupport = function isStyleValueSupport(styleName, value) {
|
|
13
|
+
if (!isStyleNameSupport(styleName)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
var ele = document.createElement('div');
|
|
17
|
+
var origin = ele.style[styleName];
|
|
18
|
+
ele.style[styleName] = value;
|
|
19
|
+
return ele.style[styleName] !== origin;
|
|
20
|
+
};
|
|
21
|
+
export function isStyleSupport(styleName, styleValue) {
|
|
22
|
+
if (!Array.isArray(styleName) && styleValue !== undefined) {
|
|
23
|
+
return isStyleValueSupport(styleName, styleValue);
|
|
24
|
+
}
|
|
25
|
+
return isStyleNameSupport(styleName);
|
|
26
|
+
}
|