export const translateString = (x, y) => `translate(${parseInt(x, 10)} ${parseInt(y, 10)})`; export const parseTranslateString = string => { if (!string) return { x: 0, y: 0 }; const g = document.createElementNS('http://www.w3.org/2000/svg', 'g'); g.setAttributeNS(null, 'transform', string); const matrix = g.transform.baseVal.consolidate().matrix; return { x: matrix.e, y: matrix.f }; }; export const isMSEdge = () => window.navigator.userAgent.indexOf('Edge') > -1; export const patchMSEdge = node => { if (isMSEdge()) { // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/4320441/ void new MutationObserver(function(muts) { for (var i = muts.length; i--; ) { var mut = muts[i], objs = (mut.target as any).querySelectorAll( 'foreignObject' ); for (var j = objs.length; j--; ) { var obj = objs[j]; var val = obj.style.display; obj.style.display = 'none'; obj.getBBox(); obj.style.display = val; } } }).observe(node, { attributes: true, attributeFilter: ['transform'], subtree: true }); } };