SourceTermAnalysisSystem_vue/node_modules/@antv/x6-common/es/unit/index.js
2026-05-15 10:22:44 +08:00

56 lines
1.5 KiB
JavaScript

let millimeterSize;
const supportedUnits = {
px(val) {
return val;
},
mm(val) {
return millimeterSize * val;
},
cm(val) {
return millimeterSize * val * 10;
},
in(val) {
return millimeterSize * val * 25.4;
},
pt(val) {
return millimeterSize * ((25.4 * val) / 72);
},
pc(val) {
return millimeterSize * ((25.4 * val) / 6);
},
};
// eslint-disable-next-line
export var Unit;
(function (Unit) {
function measure(cssWidth, cssHeight, unit) {
const div = document.createElement('div');
const style = div.style;
style.display = 'inline-block';
style.position = 'absolute';
style.left = '-15000px';
style.top = '-15000px';
style.width = cssWidth + (unit || 'px');
style.height = cssHeight + (unit || 'px');
document.body.appendChild(div);
const rect = div.getBoundingClientRect();
const size = {
width: rect.width || 0,
height: rect.height || 0,
};
document.body.removeChild(div);
return size;
}
Unit.measure = measure;
function toPx(val, unit) {
if (millimeterSize == null) {
millimeterSize = measure('1', '1', 'mm').width;
}
const convert = unit ? supportedUnits[unit] : null;
if (convert) {
return convert(val);
}
return val;
}
Unit.toPx = toPx;
})(Unit || (Unit = {}));
//# sourceMappingURL=index.js.map