1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00
vault-frontend/src/utils/dom.ts
2019-08-25 13:27:48 +07:00

58 lines
1.3 KiB
TypeScript

export const getStyle = (oElm: any, strCssRule: string) => {
if (document.defaultView && document.defaultView.getComputedStyle) {
return document.defaultView.getComputedStyle(oElm, '').getPropertyValue(strCssRule);
}
if (oElm.currentStyle) {
return oElm.currentStyle[strCssRule.replace(/-(\w)/g, (strMatch, p1) => p1.toUpperCase())];
}
return '';
};
function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
const angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;
return {
x: centerX + radius * Math.cos(angleInRadians),
y: centerY + radius * Math.sin(angleInRadians),
};
}
export const describeArc = (
x: number,
y: number,
radius: number,
startAngle: number = 0,
endAngle: number = 360
): string => {
const start = polarToCartesian(x, y, radius, endAngle);
const end = polarToCartesian(x, y, radius, startAngle);
const largeArcFlag = endAngle - startAngle <= 180 ? 0 : 1;
return [
'M',
start.x,
start.y,
'A',
radius,
radius,
0,
largeArcFlag,
0,
end.x,
end.y,
'L',
x,
y,
'L',
start.x,
start.y,
].join(' ');
};
export const getURL = url => `${process.env.API_HOST}${url}`;
export const getImageSize = (image: string, size?: string): string =>
`${process.env.API_HOST}${image}`;