var range; // Create a range object for efficently rendering strings to elements. var NS_XHTML = 'http://www.w3.org/1999/xhtml'; export var doc = typeof document === 'undefined' ? undefined : document; var HAS_TEMPLATE_SUPPORT = !!doc && 'content' in doc.createElement('template'); var HAS_RANGE_SUPPORT = !!doc && doc.createRange && 'createContextualFragment' in doc.createRange(); function createFragmentFromTemplate(str) { var template = doc.createElement('template'); template.innerHTML = str; return template.content.childNodes[0]; } function createFragmentFromRange(str) { if (!range) { range = doc.createRange(); range.selectNode(doc.body); } var fragment = range.createContextualFragment(str); return fragment.childNodes[0]; } function createFragmentFromWrap(str) { var fragment = doc.createElement('body'); fragment.innerHTML = str; return fragment.childNodes[0]; } /** * This is about the same * var html = new DOMParser().parseFromString(str, 'text/html'); * return html.body.firstChild; * * @method toElement * @param {String} str */ export function toElement(str) { str = str.trim(); if (HAS_TEMPLATE_SUPPORT) { // avoid restrictions on content for things like `Hi` which // createContextualFragment doesn't support //