dir-shadow-utils.js (697B)
1 function html_direction(element) { 2 let is_ltr = element.matches(":dir(ltr)"); 3 let is_rtl = element.matches(":dir(rtl)"); 4 if (is_ltr == is_rtl) { 5 return "error"; 6 } 7 return is_ltr ? "ltr" : "rtl"; 8 } 9 10 function setup_tree(light_tree, shadow_tree) { 11 let body = document.body; 12 let old_length = body.childNodes.length; 13 body.insertAdjacentHTML("beforeend", light_tree.trim()); 14 if (body.childNodes.length != old_length + 1) { 15 throw "unexpected markup"; 16 } 17 let result = body.lastChild; 18 if (shadow_tree) { 19 let shadow = result.querySelector("#root").attachShadow({mode: "open"}); 20 shadow.innerHTML = shadow_tree.trim(); 21 return [result, shadow]; 22 } 23 return result; 24 }