1"use strict"; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.escapeBackticksAndOctals = escapeBackticksAndOctals; 7exports.getHotReplaceTemplate = getHotReplaceTemplate; 8exports.pathToHtmlSafeName = pathToHtmlSafeName; 9exports.wrapDevelopmentCSS = wrapDevelopmentCSS; 10function pathToHtmlSafeName(path) { 11 return path.replace(/[^a-zA-Z0-9_]/g, '_'); 12} 13function getHotReplaceTemplate(id) { 14 // In dev mode, we need to replace the style tag instead of appending it 15 // use the path as the expo-css-hmr attribute to find the style tag 16 // to replace. 17 const attr = JSON.stringify(pathToHtmlSafeName(id)); 18 return `style.setAttribute('data-expo-css-hmr', ${attr}); 19 const previousStyle = document.querySelector('[data-expo-css-hmr=${attr}]'); 20 if (previousStyle) { 21 previousStyle.parentNode.removeChild(previousStyle); 22 }`; 23} 24function wrapDevelopmentCSS(props) { 25 const withBackTicksEscaped = escapeBackticksAndOctals(props.src); 26 return `(() => { 27 if (typeof document === 'undefined') { 28 return 29 } 30 const head = document.head || document.getElementsByTagName('head')[0]; 31 const style = document.createElement('style'); 32 ${getHotReplaceTemplate(props.filename)} 33 style.setAttribute('data-expo-loader', 'css'); 34 head.appendChild(style); 35 const css = \`${withBackTicksEscaped}\`; 36 if (style.styleSheet){ 37 style.styleSheet.cssText = css; 38 } else { 39 style.appendChild(document.createTextNode(css)); 40 } 41})();`; 42} 43function escapeBackticksAndOctals(str) { 44 if (typeof str !== 'string') { 45 return ''; 46 } 47 return str.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/[\0-\7]/g, match => `\\0${match.charCodeAt(0).toString(8)}`); 48} 49//# sourceMappingURL=css.js.map