2021-06-07 17:35:03 +08:00
|
|
|
import canUseDom from './canUseDom';
|
|
|
|
|
|
|
|
export const canUseDocElement = () => canUseDom() && window.document.documentElement;
|
|
|
|
|
2022-03-12 09:56:32 +08:00
|
|
|
const isStyleNameSupport = (styleName: string | string[]): boolean => {
|
|
|
|
if (canUseDom() && window.document.documentElement) {
|
2019-09-05 22:18:27 +08:00
|
|
|
const styleNameList = Array.isArray(styleName) ? styleName : [styleName];
|
|
|
|
const { documentElement } = window.document;
|
|
|
|
|
|
|
|
return styleNameList.some(name => name in documentElement.style);
|
|
|
|
}
|
|
|
|
return false;
|
2020-03-07 19:45:13 +08:00
|
|
|
};
|
2019-09-05 22:18:27 +08:00
|
|
|
|
2022-03-12 09:56:32 +08:00
|
|
|
const isStyleValueSupport = (styleName: string, value: any) => {
|
|
|
|
if (!isStyleNameSupport(styleName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ele = document.createElement('div');
|
|
|
|
const origin = ele.style[styleName];
|
|
|
|
ele.style[styleName] = value;
|
|
|
|
return ele.style[styleName] !== origin;
|
|
|
|
};
|
|
|
|
|
|
|
|
export function isStyleSupport(styleName: string | string[], styleValue?: any) {
|
|
|
|
if (!Array.isArray(styleName) && styleValue !== undefined) {
|
|
|
|
return isStyleValueSupport(styleName, styleValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return isStyleNameSupport(styleName);
|
|
|
|
}
|
|
|
|
|
2021-06-07 17:35:03 +08:00
|
|
|
let flexGapSupported: boolean | undefined;
|
|
|
|
export const detectFlexGapSupported = () => {
|
|
|
|
if (!canUseDocElement()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flexGapSupported !== undefined) {
|
|
|
|
return flexGapSupported;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
flexGapSupported = flex.scrollHeight === 1; // flex container should be 1px high from the row-gap
|
|
|
|
document.body.removeChild(flex);
|
|
|
|
|
|
|
|
return flexGapSupported;
|
|
|
|
};
|
2019-09-05 22:18:27 +08:00
|
|
|
|
|
|
|
export default isStyleSupport;
|