/** * Class Applier module for Rangy. * Adds, removes and toggles classes on Ranges and Selections * * Part of Rangy, a cross-browser JavaScript range and selection library * https://github.com/timdown/rangy * * Depends on Rangy core. * * Copyright 2024, Tim Down * Licensed under the MIT license. * Version: 1.3.2 * Build date: 2 November 2024 */ export declare const classApplier = "\n(function(factory, root) {\n if (typeof define == \"function\" && define.amd) {\n // AMD. Register as an anonymous module with a dependency on Rangy.\n define([\"./rangy-core\"], factory);\n } else if (typeof module != \"undefined\" && typeof exports == \"object\") {\n // Node/CommonJS style\n module.exports = factory( require(\"rangy\") );\n } else {\n // No AMD or CommonJS support so we use the rangy property of root (probably the global variable)\n factory(root.rangy);\n}\n})(function(rangy) {\n rangy.createModule(\"ClassApplier\", [\"WrappedSelection\"], function(api, module) {\n var dom = api.dom;\n var DomPosition = dom.DomPosition;\n var contains = dom.arrayContains;\n var util = api.util;\n var forEach = util.forEach;\n\n\n var defaultTagName = \"span\";\n var createElementNSSupported = util.isHostMethod(document, \"createElementNS\");\n\n function each(obj, func) {\n for (var i in obj) {\n if (obj.hasOwnProperty(i)) {\n if (func(i, obj[i]) === false) {\n return false;\n }\n }\n }\n return true;\n }\n\n function trim(str) {\n return str.replace(/^\\s\\s*/, \"\").replace(/\\s\\s*$/, \"\");\n }\n\n function classNameContainsClass(fullClassName, className) {\n return !!fullClassName && new RegExp(\"(?:^|\\\\s)\" + className + \"(?:\\\\s|$)\").test(fullClassName);\n }\n\n // Inefficient, inelegant nonsense for IE's svg element, which has no classList and non-HTML className implementation\n function hasClass(el, className) {\n if (typeof el.classList == \"object\") {\n return el.classList.contains(className);\n } else {\n var classNameSupported = (typeof el.className == \"string\");\n var elClass = classNameSupported ? el.className : el.getAttribute(\"class\");\n return classNameContainsClass(elClass, className);\n }\n }\n\n function addClass(el, className) {\n if (typeof el.classList == \"object\") {\n el.classList.add(className);\n } else {\n var classNameSupported = (typeof el.className == \"string\");\n var elClass = classNameSupported ? el.className : el.getAttribute(\"class\");\n if (elClass) {\n if (!classNameContainsClass(elClass, className)) {\n elClass += \" \" + className;\n }\n } else {\n elClass = className;\n }\n if (classNameSupported) {\n el.className = elClass;\n } else {\n el.setAttribute(\"class\", elClass);\n}\n}\n}\n\nvar removeClass = (function() {\n function replacer(matched, whiteSpaceBefore, whiteSpaceAfter) {\n return (whiteSpaceBefore && whiteSpaceAfter) ? \" \" : \"\";\n }\n\n return function(el, className) {\n if (typeof el.classList == \"object\") {\n el.classList.remove(className);\n } else {\n var classNameSupported = (typeof el.className == \"string\");\n var elClass = classNameSupported ? el.className : el.getAttribute(\"class\");\n elClass = elClass.replace(new RegExp(\"(^|\\\\s)\" + className + \"(\\\\s|$)\"), replacer);\n if (classNameSupported) {\n el.className = elClass;\n } else {\n el.setAttribute(\"class\", elClass);\n }\n}\n};\n})();\n\nfunction getClass(el) {\n var classNameSupported = (typeof el.className == \"string\");\n return classNameSupported ? el.className : el.getAttribute(\"class\");\n}\n\nfunction sortClassName(className) {\n return className && className.split(/\\s+/).sort().join(\" \");\n}\n\nfunction getSortedClassName(el) {\n return sortClassName( getClass(el) );\n}\n\nfunction haveSameClasses(el1, el2) {\n return getSortedClassName(el1) == getSortedClassName(el2);\n}\n\nfunction hasAllClasses(el, className) {\n var classes = className.split(/\\s+/);\n for (var i = 0, len = classes.length; i < len; ++i) {\n if (!hasClass(el, trim(classes[i]))) {\n return false;\n }\n }\n return true;\n}\n\nfunction canTextBeStyled(textNode) {\n var parent = textNode.parentNode;\n return (parent && parent.nodeType == 1 && !/^(textarea|style|script|select|iframe)$/i.test(parent.nodeName));\n}\n\nfunction movePosition(position, oldParent, oldIndex, newParent, newIndex) {\n var posNode = position.node, posOffset = position.offset;\n var newNode = posNode, newOffset = posOffset;\n\n if (posNode == newParent && posOffset > newIndex) {\n ++newOffset;\n }\n\n if (posNode == oldParent && (posOffset == oldIndex || posOffset == oldIndex + 1)) {\n newNode = newParent;\n newOffset += newIndex - oldIndex;\n }\n\n if (posNode == oldParent && posOffset > oldIndex + 1) {\n --newOffset;\n }\n\n position.node = newNode;\n position.offset = newOffset;\n}\n\nfunction movePositionWhenRemovingNode(position, parentNode, index) {\n if (position.node == parentNode && position.offset > index) {\n --position.offset;\n }\n}\n\nfunction movePreservingPositions(node, newParent, newIndex, positionsToPreserve) {\n // For convenience, allow newIndex to be -1 to mean \"insert at the end\".\n if (newIndex == -1) {\n newIndex = newParent.childNodes.length;\n }\n\n var oldParent = node.parentNode;\n var oldIndex = dom.getNodeIndex(node);\n\n forEach(positionsToPreserve, function(position) {\n movePosition(position, oldParent, oldIndex, newParent, newIndex);\n });\n\n // Now actually move the node.\n if (newParent.childNodes.length == newIndex) {\n newParent.appendChild(node);\n } else {\n newParent.insertBefore(node, newParent.childNodes[newIndex]);\n}\n}\n\nfunction removePreservingPositions(node, positionsToPreserve) {\n\nvar oldParent = node.parentNode;\nvar oldIndex = dom.getNodeIndex(node);\n\nforEach(positionsToPreserve, function(position) {\n movePositionWhenRemovingNode(position, oldParent, oldIndex);\n});\n\ndom.removeNode(node);\n}\n\nfunction moveChildrenPreservingPositions(node, newParent, newIndex, removeNode, positionsToPreserve) {\n var child, children = [];\n while ( (child = node.firstChild) ) {\n movePreservingPositions(child, newParent, newIndex++, positionsToPreserve);\n children.push(child);\n }\n if (removeNode) {\n removePreservingPositions(node, positionsToPreserve);\n }\n return children;\n}\n\nfunction replaceWithOwnChildrenPreservingPositions(element, positionsToPreserve) {\n return moveChildrenPreservingPositions(element, element.parentNode, dom.getNodeIndex(element), true, positionsToPreserve);\n}\n\nfunction rangeSelectsAnyText(range, textNode) {\n var textNodeRange = range.cloneRange();\n textNodeRange.selectNodeContents(textNode);\n\n var intersectionRange = textNodeRange.intersection(range);\n var text = intersectionRange ? intersectionRange.toString() : \"\";\n\n return text != \"\";\n}\n\nfunction getEffectiveTextNodes(range) {\n var nodes = range.getNodes([3]);\n\n // Optimization as per issue 145\n\n // Remove non-intersecting text nodes from the start of the range\n var start = 0, node;\n while ( (node = nodes[start]) && !rangeSelectsAnyText(range, node) ) {\n ++start;\n }\n\n // Remove non-intersecting text nodes from the start of the range\n var end = nodes.length - 1;\n while ( (node = nodes[end]) && !rangeSelectsAnyText(range, node) ) {\n --end;\n }\n\n return nodes.slice(start, end + 1);\n}\n\nfunction elementsHaveSameNonClassAttributes(el1, el2) {\n if (el1.attributes.length != el2.attributes.length) return false;\n for (var i = 0, len = el1.attributes.length, attr1, attr2, name; i < len; ++i) {\n attr1 = el1.attributes[i];\n name = attr1.name;\n if (name != \"class\") {\n attr2 = el2.attributes.getNamedItem(name);\n if ( (attr1 === null) != (attr2 === null) ) return false;\n if (attr1.specified != attr2.specified) return false;\n if (attr1.specified && attr1.nodeValue !== attr2.nodeValue) return false;\n }\n }\n return true;\n}\n\nfunction elementHasNonClassAttributes(el, exceptions) {\n for (var i = 0, len = el.attributes.length, attrName; i < len; ++i) {\n attrName = el.attributes[i].name;\n if ( !(exceptions && contains(exceptions, attrName)) && el.attributes[i].specified && attrName != \"class\") {\n return true;\n }\n }\n return false;\n}\n\nvar getComputedStyleProperty = dom.getComputedStyleProperty;\nvar isEditableElement = (function() {\n var testEl = document.createElement(\"div\");\n return typeof testEl.isContentEditable == \"boolean\" ?\n function (node) {\n return node && node.nodeType == 1 && node.isContentEditable;\n } :\n function (node) {\n if (!node || node.nodeType != 1 || node.contentEditable == \"false\") {\n return false;\n }\n return node.contentEditable == \"true\" || isEditableElement(node.parentNode);\n };\n})();\n\nfunction isEditingHost(node) {\n var parent;\n return node && node.nodeType == 1 &&\n (( (parent = node.parentNode) && parent.nodeType == 9 && parent.designMode == \"on\") ||\n (isEditableElement(node) && !isEditableElement(node.parentNode)));\n}\n\nfunction isEditable(node) {\n return (isEditableElement(node) || (node.nodeType != 1 && isEditableElement(node.parentNode))) && !isEditingHost(node);\n}\n\nvar inlineDisplayRegex = /^inline(-block|-table)?$/i;\n\nfunction isNonInlineElement(node) {\n return node && node.nodeType == 1 && !inlineDisplayRegex.test(getComputedStyleProperty(node, \"display\"));\n}\n\n// White space characters as defined by HTML 4 (http://www.w3.org/TR/html401/struct/text.html)\nvar htmlNonWhiteSpaceRegex = /[^\\r\\n\\t\\f \\u200B]/;\n\nfunction isUnrenderedWhiteSpaceNode(node) {\n if (node.data.length == 0) {\n return true;\n }\n if (htmlNonWhiteSpaceRegex.test(node.data)) {\n return false;\n }\n var cssWhiteSpace = getComputedStyleProperty(node.parentNode, \"whiteSpace\");\n switch (cssWhiteSpace) {\n case \"pre\":\n case \"pre-wrap\":\n case \"-moz-pre-wrap\":\n return false;\n case \"pre-line\":\n if (/[\\r\\n]/.test(node.data)) {\n return false;\n }\n }\n\n // We now have a whitespace-only text node that may be rendered depending on its context. If it is adjacent to a\n // non-inline element, it will not be rendered. This seems to be a good enough definition.\n return isNonInlineElement(node.previousSibling) || isNonInlineElement(node.nextSibling);\n }\n\n function getRangeBoundaries(ranges) {\n var positions = [], i, range;\n for (i = 0; range = ranges[i++]; ) {\n positions.push(\n new DomPosition(range.startContainer, range.startOffset),\n new DomPosition(range.endContainer, range.endOffset)\n );\n }\n return positions;\n }\n\n function updateRangesFromBoundaries(ranges, positions) {\n for (var i = 0, range, start, end, len = ranges.length; i < len; ++i) {\n range = ranges[i];\n start = positions[i * 2];\n end = positions[i * 2 + 1];\n range.setStartAndEnd(start.node, start.offset, end.node, end.offset);\n }\n }\n\n function isSplitPoint(node, offset) {\n if (dom.isCharacterDataNode(node)) {\n if (offset == 0) {\n return !!node.previousSibling;\n } else if (offset == node.length) {\n return !!node.nextSibling;\n } else {\n return true;\n }\n }\n\n return offset > 0 && offset < node.childNodes.length;\n }\n\n function splitNodeAt(node, descendantNode, descendantOffset, positionsToPreserve) {\n var newNode, parentNode;\n var splitAtStart = (descendantOffset == 0);\n\n if (dom.isAncestorOf(descendantNode, node)) {\n return node;\n }\n\n if (dom.isCharacterDataNode(descendantNode)) {\n var descendantIndex = dom.getNodeIndex(descendantNode);\n if (descendantOffset == 0) {\n descendantOffset = descendantIndex;\n } else if (descendantOffset == descendantNode.length) {\n descendantOffset = descendantIndex + 1;\n } else {\n throw module.createError(\"splitNodeAt() should not be called with offset in the middle of a data node (\" +\n descendantOffset + \" in \" + descendantNode.data);\n }\n descendantNode = descendantNode.parentNode;\n }\n\n if (isSplitPoint(descendantNode, descendantOffset)) {\n // descendantNode is now guaranteed not to be a text or other character node\n newNode = descendantNode.cloneNode(false);\n parentNode = descendantNode.parentNode;\n if (newNode.id) {\n newNode.removeAttribute(\"id\");\n }\n var child, newChildIndex = 0;\n\n while ( (child = descendantNode.childNodes[descendantOffset]) ) {\n movePreservingPositions(child, newNode, newChildIndex++, positionsToPreserve);\n }\n movePreservingPositions(newNode, parentNode, dom.getNodeIndex(descendantNode) + 1, positionsToPreserve);\n return (descendantNode == node) ? newNode : splitNodeAt(node, parentNode, dom.getNodeIndex(newNode), positionsToPreserve);\n } else if (node != descendantNode) {\n newNode = descendantNode.parentNode;\n\n // Work out a new split point in the parent node\n var newNodeIndex = dom.getNodeIndex(descendantNode);\n\n if (!splitAtStart) {\n newNodeIndex++;\n }\n return splitNodeAt(node, newNode, newNodeIndex, positionsToPreserve);\n }\n return node;\n }\n\n function areElementsMergeable(el1, el2) {\n return el1.namespaceURI == el2.namespaceURI &&\n el1.tagName.toLowerCase() == el2.tagName.toLowerCase() &&\n haveSameClasses(el1, el2) &&\n elementsHaveSameNonClassAttributes(el1, el2) &&\n getComputedStyleProperty(el1, \"display\") == \"inline\" &&\n getComputedStyleProperty(el2, \"display\") == \"inline\";\n }\n\n function createAdjacentMergeableTextNodeGetter(forward) {\n var siblingPropName = forward ? \"nextSibling\" : \"previousSibling\";\n\n return function(textNode, checkParentElement) {\n var el = textNode.parentNode;\n var adjacentNode = textNode[siblingPropName];\n if (adjacentNode) {\n // Can merge if the node's previous/next sibling is a text node\n if (adjacentNode && adjacentNode.nodeType == 3) {\n return adjacentNode;\n }\n } else if (checkParentElement) {\n // Compare text node parent element with its sibling\n adjacentNode = el[siblingPropName];\n if (adjacentNode && adjacentNode.nodeType == 1 && areElementsMergeable(el, adjacentNode)) {\n var adjacentNodeChild = adjacentNode[forward ? \"firstChild\" : \"lastChild\"];\n if (adjacentNodeChild && adjacentNodeChild.nodeType == 3) {\n return adjacentNodeChild;\n }\n }\n }\n return null;\n };\n }\n\n var getPreviousMergeableTextNode = createAdjacentMergeableTextNodeGetter(false),\n getNextMergeableTextNode = createAdjacentMergeableTextNodeGetter(true);\n\n\n function Merge(firstNode) {\n this.isElementMerge = (firstNode.nodeType == 1);\n this.textNodes = [];\n var firstTextNode = this.isElementMerge ? firstNode.lastChild : firstNode;\n if (firstTextNode) {\n this.textNodes[0] = firstTextNode;\n }\n }\n\n Merge.prototype = {\n doMerge: function(positionsToPreserve) {\n var textNodes = this.textNodes;\n var firstTextNode = textNodes[0];\n if (textNodes.length > 1) {\n var firstTextNodeIndex = dom.getNodeIndex(firstTextNode);\n var textParts = [], combinedTextLength = 0, textNode, parent;\n forEach(textNodes, function(textNode, i) {\n parent = textNode.parentNode;\n if (i > 0) {\n parent.removeChild(textNode);\n if (!parent.hasChildNodes()) {\n dom.removeNode(parent);\n }\n if (positionsToPreserve) {\n forEach(positionsToPreserve, function(position) {\n // Handle case where position is inside the text node being merged into a preceding node\n if (position.node == textNode) {\n position.node = firstTextNode;\n position.offset += combinedTextLength;\n }\n // Handle case where both text nodes precede the position within the same parent node\n if (position.node == parent && position.offset > firstTextNodeIndex) {\n --position.offset;\n if (position.offset == firstTextNodeIndex + 1 && i < textNodes.length - 1) {\n position.node = firstTextNode;\n position.offset = combinedTextLength;\n }\n }\n });\n }\n }\n textParts[i] = textNode.data;\n combinedTextLength += textNode.data.length;\n });\n firstTextNode.data = textParts.join(\"\");\n }\n return firstTextNode.data;\n },\n\n getLength: function() {\n var i = this.textNodes.length, len = 0;\n while (i--) {\n len += this.textNodes[i].length;\n }\n return len;\n },\n\n toString: function() {\n var textParts = [];\n forEach(this.textNodes, function(textNode, i) {\n textParts[i] = \"'\" + textNode.data + \"'\";\n });\n return \"[Merge(\" + textParts.join(\",\") + \")]\";\n }\n };\n\n var optionProperties = [\"elementTagName\", \"ignoreWhiteSpace\", \"applyToEditableOnly\", \"useExistingElements\",\n \"removeEmptyElements\", \"onElementCreate\"];\n\n // TODO: Populate this with every attribute name that corresponds to a property with a different name. Really??\n var attrNamesForProperties = {};\n\n function ClassApplier(className, options, tagNames) {\n var normalize, i, len, propName, applier = this;\n applier.cssClass = applier.className = className; // cssClass property is for backward compatibility\n\n var elementPropertiesFromOptions = null, elementAttributes = {};\n\n // Initialize from options object\n if (typeof options == \"object\" && options !== null) {\n if (typeof options.elementTagName !== \"undefined\") {\n options.elementTagName = options.elementTagName.toLowerCase();\n }\n tagNames = options.tagNames;\n elementPropertiesFromOptions = options.elementProperties;\n elementAttributes = options.elementAttributes;\n\n for (i = 0; propName = optionProperties[i++]; ) {\n if (options.hasOwnProperty(propName)) {\n applier[propName] = options[propName];\n }\n }\n normalize = options.normalize;\n } else {\n normalize = options;\n }\n\n // Backward compatibility: the second parameter can also be a Boolean indicating to normalize after unapplying\n applier.normalize = (typeof normalize == \"undefined\") ? true : normalize;\n\n // Initialize element properties and attribute exceptions\n applier.attrExceptions = [];\n var el = document.createElement(applier.elementTagName);\n applier.elementProperties = applier.copyPropertiesToElement(elementPropertiesFromOptions, el, true);\n each(elementAttributes, function(attrName, attrValue) {\n applier.attrExceptions.push(attrName);\n // Ensure each attribute value is a string\n elementAttributes[attrName] = \"\" + attrValue;\n });\n applier.elementAttributes = elementAttributes;\n\n applier.elementSortedClassName = applier.elementProperties.hasOwnProperty(\"className\") ?\n sortClassName(applier.elementProperties.className + \" \" + className) : className;\n\n // Initialize tag names\n applier.applyToAnyTagName = false;\n var type = typeof tagNames;\n if (type == \"string\") {\n if (tagNames == \"*\") {\n applier.applyToAnyTagName = true;\n } else {\n applier.tagNames = trim(tagNames.toLowerCase()).split(/\\s*,\\s*/);\n }\n } else if (type == \"object\" && typeof tagNames.length == \"number\") {\n applier.tagNames = [];\n for (i = 0, len = tagNames.length; i < len; ++i) {\n if (tagNames[i] == \"*\") {\n applier.applyToAnyTagName = true;\n } else {\n applier.tagNames.push(tagNames[i].toLowerCase());\n }\n }\n} else {\n applier.tagNames = [applier.elementTagName];\n}\n}\n\nClassApplier.prototype = {\n elementTagName: defaultTagName,\n elementProperties: {},\n elementAttributes: {},\n ignoreWhiteSpace: true,\n applyToEditableOnly: false,\n useExistingElements: true,\n removeEmptyElements: true,\n onElementCreate: null,\n\n copyPropertiesToElement: function(props, el, createCopy) {\n var s, elStyle, elProps = {}, elPropsStyle, propValue, elPropValue, attrName;\n\n for (var p in props) {\n if (props.hasOwnProperty(p)) {\n propValue = props[p];\n elPropValue = el[p];\n\n // Special case for class. The copied properties object has the applier's class as well as its own\n // to simplify checks when removing styling elements\n if (p == \"className\") {\n addClass(el, propValue);\n addClass(el, this.className);\n el[p] = sortClassName(el[p]);\n if (createCopy) {\n elProps[p] = propValue;\n }\n }\n\n // Special case for style\n else if (p == \"style\") {\n elStyle = elPropValue;\n if (createCopy) {\n elProps[p] = elPropsStyle = {};\n }\n for (s in props[p]) {\n if (props[p].hasOwnProperty(s)) {\n elStyle[s] = propValue[s];\n if (createCopy) {\n elPropsStyle[s] = elStyle[s];\n }\n }\n }\n this.attrExceptions.push(p);\n } else {\n el[p] = propValue;\n // Copy the property back from the dummy element so that later comparisons to check whether\n // elements may be removed are checking against the right value. For example, the href property\n // of an element returns a fully qualified URL even if it was previously assigned a relative\n // URL.\n if (createCopy) {\n elProps[p] = el[p];\n\n // Not all properties map to identically-named attributes\n attrName = attrNamesForProperties.hasOwnProperty(p) ? attrNamesForProperties[p] : p;\n this.attrExceptions.push(attrName);\n }\n }\n }\n }\n\n return createCopy ? elProps : \"\";\n},\n\ncopyAttributesToElement: function(attrs, el) {\n for (var attrName in attrs) {\n if (attrs.hasOwnProperty(attrName) && !/^class(?:Name)?$/i.test(attrName)) {\n el.setAttribute(attrName, attrs[attrName]);\n }\n }\n},\n\nappliesToElement: function(el) {\n return contains(this.tagNames, el.tagName.toLowerCase());\n},\n\ngetEmptyElements: function(range) {\n var applier = this;\n return range.getNodes([1], function(el) {\n return applier.appliesToElement(el) && !el.hasChildNodes();\n });\n},\n\nhasClass: function(node) {\n return node.nodeType == 1 &&\n (this.applyToAnyTagName || this.appliesToElement(node)) &&\n hasClass(node, this.className);\n},\n\ngetSelfOrAncestorWithClass: function(node) {\n while (node) {\n if (this.hasClass(node)) {\n return node;\n }\n node = node.parentNode;\n }\n return null;\n},\n\nisModifiable: function(node) {\n return !this.applyToEditableOnly || isEditable(node);\n},\n\n// White space adjacent to an unwrappable node can be ignored for wrapping\nisIgnorableWhiteSpaceNode: function(node) {\n return this.ignoreWhiteSpace && node && node.nodeType == 3 && isUnrenderedWhiteSpaceNode(node);\n},\n\n// Normalizes nodes after applying a class to a Range.\npostApply: function(textNodes, range, positionsToPreserve, isUndo) {\n var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];\n var merges = [], currentMerge;\n var rangeStartNode = firstNode, rangeEndNode = lastNode;\n var rangeStartOffset = 0, rangeEndOffset = lastNode.length;\n var precedingTextNode;\n\n // Check for every required merge and create a Merge object for each\n forEach(textNodes, function(textNode) {\n precedingTextNode = getPreviousMergeableTextNode(textNode, !isUndo);\n if (precedingTextNode) {\n if (!currentMerge) {\n currentMerge = new Merge(precedingTextNode);\n merges.push(currentMerge);\n }\n currentMerge.textNodes.push(textNode);\n if (textNode === firstNode) {\n rangeStartNode = currentMerge.textNodes[0];\n rangeStartOffset = rangeStartNode.length;\n }\n if (textNode === lastNode) {\n rangeEndNode = currentMerge.textNodes[0];\n rangeEndOffset = currentMerge.getLength();\n }\n } else {\n currentMerge = null;\n }\n});\n\n// Test whether the first node after the range needs merging\nvar nextTextNode = getNextMergeableTextNode(lastNode, !isUndo);\n\nif (nextTextNode) {\n if (!currentMerge) {\n currentMerge = new Merge(lastNode);\n merges.push(currentMerge);\n }\n currentMerge.textNodes.push(nextTextNode);\n}\n\n// Apply the merges\nif (merges.length) {\n for (var i = 0, len = merges.length; i < len; ++i) {\n merges[i].doMerge(positionsToPreserve);\n }\n\n // Set the range boundaries\n range.setStartAndEnd(rangeStartNode, rangeStartOffset, rangeEndNode, rangeEndOffset);\n}\n},\n\ncreateContainer: function(parentNode) {\n var doc = dom.getDocument(parentNode);\n var namespace;\n var el = createElementNSSupported && !dom.isHtmlNamespace(parentNode) && (namespace = parentNode.namespaceURI) ?\n doc.createElementNS(parentNode.namespaceURI, this.elementTagName) :\n doc.createElement(this.elementTagName);\n\n this.copyPropertiesToElement(this.elementProperties, el, false);\n this.copyAttributesToElement(this.elementAttributes, el);\n addClass(el, this.className);\n if (this.onElementCreate) {\n this.onElementCreate(el, this);\n }\n return el;\n},\n\nelementHasProperties: function(el, props) {\n var applier = this;\n return each(props, function(p, propValue) {\n if (p == \"className\") {\n // For checking whether we should reuse an existing element, we just want to check that the element\n // has all the classes specified in the className property. When deciding whether the element is\n // removable when unapplying a class, there is separate special handling to check whether the\n // element has extra classes so the same simple check will do.\n return hasAllClasses(el, propValue);\n } else if (typeof propValue == \"object\") {\n if (!applier.elementHasProperties(el[p], propValue)) {\n return false;\n }\n } else if (el[p] !== propValue) {\n return false;\n }\n });\n},\n\nelementHasAttributes: function(el, attrs) {\n return each(attrs, function(name, value) {\n if (el.getAttribute(name) !== value) {\n return false;\n }\n });\n},\n\napplyToTextNode: function(textNode, positionsToPreserve) {\n\n// Check whether the text node can be styled. Text within a