2021-02-01 10:15:39 +08:00
|
|
|
import canUseDom from 'rc-util/lib/Dom/canUseDom';
|
2021-09-15 14:13:32 +08:00
|
|
|
import { isStyleSupport } from 'rc-util/lib/Dom/styleChecker';
|
2021-02-01 10:15:39 +08:00
|
|
|
|
|
|
|
export const canUseDocElement = () => canUseDom() && window.document.documentElement;
|
|
|
|
|
2021-09-15 14:13:32 +08:00
|
|
|
export { isStyleSupport };
|
2019-01-26 11:55:53 +08:00
|
|
|
|
2023-01-16 09:55:52 +08:00
|
|
|
let flexGapSupported: boolean;
|
2021-02-03 15:39:51 +08:00
|
|
|
export const detectFlexGapSupported = () => {
|
2021-02-01 10:15:39 +08:00
|
|
|
if (!canUseDocElement()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-03 15:39:51 +08:00
|
|
|
if (flexGapSupported !== undefined) {
|
|
|
|
return flexGapSupported;
|
|
|
|
}
|
|
|
|
|
2021-02-01 10:15:39 +08:00
|
|
|
// create flex container with row-gap set
|
|
|
|
const flex = document.createElement('div');
|
|
|
|
flex.style.display = 'flex';
|
|
|
|
flex.style.flexDirection = 'column';
|
|
|
|
flex.style.rowGap = '1px';
|
|
|
|
|
|
|
|
// create two, elements inside it
|
|
|
|
flex.appendChild(document.createElement('div'));
|
|
|
|
flex.appendChild(document.createElement('div'));
|
|
|
|
|
|
|
|
// append to the DOM (needed to obtain scrollHeight)
|
|
|
|
document.body.appendChild(flex);
|
2021-02-03 15:39:51 +08:00
|
|
|
flexGapSupported = flex.scrollHeight === 1; // flex container should be 1px high from the row-gap
|
2021-02-01 10:15:39 +08:00
|
|
|
document.body.removeChild(flex);
|
|
|
|
|
2021-02-03 15:39:51 +08:00
|
|
|
return flexGapSupported;
|
|
|
|
};
|