mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
/* @flow */
|
|
'use strict';
|
|
|
|
const testRangeBounds = document => {
|
|
const TEST_HEIGHT = 123;
|
|
|
|
if (document.createRange) {
|
|
const range = document.createRange();
|
|
if (range.getBoundingClientRect) {
|
|
const testElement = document.createElement('boundtest');
|
|
testElement.style.height = `${TEST_HEIGHT}px`;
|
|
testElement.style.display = 'block';
|
|
document.body.appendChild(testElement);
|
|
|
|
range.selectNode(testElement);
|
|
const rangeBounds = range.getBoundingClientRect();
|
|
const rangeHeight = Math.round(rangeBounds.height);
|
|
document.body.removeChild(testElement);
|
|
if (rangeHeight === TEST_HEIGHT) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
const FEATURES = {
|
|
// $FlowFixMe - get/set properties not yet supported
|
|
get SUPPORT_RANGE_BOUNDS() {
|
|
'use strict';
|
|
const value = testRangeBounds(document);
|
|
Object.defineProperty(FEATURES, 'SUPPORT_RANGE_BOUNDS', {value});
|
|
return value;
|
|
}
|
|
};
|
|
|
|
export default FEATURES;
|