index.js (804B)
1 function cached(f) { 2 var cache = {}; 3 return function(arg) { 4 if (!(arg in cache)) { 5 cache[arg] = f(arg); 6 } 7 return cache[arg]; 8 }; 9 } 10 11 function iconFromBackgroundImage(className) { 12 const container = document.createElement('div'); 13 container.style.position = 'absolute'; 14 document.body.appendChild(container); 15 const el = document.createElement('div'); 16 el.className = className; 17 container.appendChild(el); 18 const st = window.getComputedStyle(el), 19 url = st.backgroundImage.replace(/^url\("?/u, '').replace(/"?\)$/u, ''); 20 let icon = {url: url, center: [-el.offsetLeft, -el.offsetTop]}; 21 document.body.removeChild(container); 22 container.removeChild(el); 23 return icon; 24 } 25 26 export default cached(iconFromBackgroundImage);