-
Notifications
You must be signed in to change notification settings - Fork 5
/
rangy-core.min.js
10 lines (10 loc) · 46.8 KB
/
rangy-core.min.js
1
2
3
4
5
6
7
8
9
10
/**
* Rangy, a cross-browser JavaScript range and selection library
* https://github.com/timdown/rangy
*
* Copyright 2024, Tim Down
* Licensed under the MIT license.
* Version: 1.3.2
* Build date: 2 November 2024
*/
!function(e,t){"function"==typeof define&&define.amd?define(e):"undefined"!=typeof module&&"object"==typeof exports?module.exports=e():t.rangy=e()}((function(){var e="object",t="undefined",n=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],r=["setStart","setStartBefore","setStartAfter","setEnd","setEndBefore","setEndAfter","collapse","selectNode","selectNodeContents","compareBoundaryPoints","deleteContents","extractContents","cloneContents","insertNode","surroundContents","cloneRange","toString","detach"],o=["boundingHeight","boundingLeft","boundingTop","boundingWidth","htmlText","text"],i=["collapse","compareEndPoints","duplicate","moveToElementText","parentElement","select","setEndPoint","getBoundingClientRect"];function a(t,n){var r=typeof t[n];return"function"==r||!(r!=e||!t[n])||"unknown"==r}function s(t,n){return!(typeof t[n]!=e||!t[n])}function c(e,n){return typeof e[n]!=t}function d(e){return function(t,n){for(var r=n.length;r--;)if(!e(t,n[r]))return!1;return!0}}var f=d(a),u=d(s),l=d(c);function h(e){return e&&f(e,i)&&l(e,o)}function g(e){return s(e,"body")?e.body:e.getElementsByTagName("body")[0]}var p,m,R={},v=typeof window!=t&&typeof document!=t,C={isHostMethod:a,isHostObject:s,isHostProperty:c,areHostMethods:f,areHostObjects:u,areHostProperties:l,isTextRange:h,getBody:g,forEach:[].forEach?function(e,t){e.forEach(t)}:function(e,t){for(var n=0,r=e.length;n<r;++n)t(e[n],n)}},N={version:"1.3.2",initialized:!1,isBrowser:v,supported:!0,util:C,features:{},modules:R,config:{alertOnFail:!1,alertOnWarn:!1,preferTextRange:!1,autoInitialize:typeof rangyAutoInitialize==t||rangyAutoInitialize}};function E(e){typeof console!=t&&a(console,"log")&&console.log(e)}function S(e,t){v&&t?alert(e):E(e)}function y(e){N.initialized=!0,N.supported=!1,S("Rangy is not supported in this environment. Reason: "+e,N.config.alertOnFail)}N.fail=y,N.warn=function(e){S("Rangy warning: "+e,N.config.alertOnWarn)},!{}.hasOwnProperty?y("hasOwnProperty not supported"):(C.extend=p=function(e,t,n){var r,o;for(var i in t)"__proto__"!==i&&"constructor"!==i&&"prototype"!==i&&t.hasOwnProperty(i)&&(r=e[i],o=t[i],n&&null!==r&&"object"==typeof r&&null!==o&&"object"==typeof o&&p(r,o,!0),e[i]=o);return t.hasOwnProperty("toString")&&(e.toString=t.toString),e},C.createOptions=function(e,t){var n={};return p(n,t),e&&p(n,e),n}),v||y("Rangy can only run in a browser"),function(){var e;if(v){var t=document.createElement("div");t.appendChild(document.createElement("span"));var n=[].slice;try{1==n.call(t.childNodes,0)[0].nodeType&&(e=function(e){return n.call(e,0)})}catch(e){}}e||(e=function(e){for(var t=[],n=0,r=e.length;n<r;++n)t[n]=e[n];return t}),C.toArray=e}(),v&&(a(document,"addEventListener")?m=function(e,t,n){e.addEventListener(t,n,!1)}:a(document,"attachEvent")?m=function(e,t,n){e.attachEvent("on"+t,n)}:y("Document does not have required addEventListener or attachEvent method"),C.addListener=m);var w=[];function T(e){return e.message||e.description||String(e)}function O(){if(v&&!N.initialized){var e,t=!1,o=!1;a(document,"createRange")&&(e=document.createRange(),f(e,r)&&l(e,n)&&(t=!0));var i=g(document);if(i&&"body"==i.nodeName.toLowerCase())if(i&&a(i,"createTextRange")&&h(e=i.createTextRange())&&(o=!0),t||o){var s;for(var c in N.initialized=!0,N.features={implementsDomRange:t,implementsTextRange:o},R)(s=R[c])instanceof x&&s.init(s,N);for(var d=0,u=w.length;d<u;++d)try{w[d](N)}catch(e){E("Rangy init listener threw an exception. Continuing. Detail: "+T(e))}}else y("Neither Range nor TextRange are available");else y("No body element found")}}function _(e,t,n){n&&(e+=" in module "+n.name),N.warn("DEPRECATED: "+e+" is deprecated. Please use "+t+" instead.")}function D(e,t,n,r){e[t]=function(){return _(t,n,r),e[n].apply(e,C.toArray(arguments))}}C.deprecationNotice=_,C.createAliasForDeprecatedMethod=D,N.init=O,N.addInitListener=function(e){N.initialized?e(N):w.push(e)};var A=[];function x(e,t,n){this.name=e,this.dependencies=t,this.initialized=!1,this.supported=!1,this.initializer=n}function b(e,t,n){var r=new x(e,t,(function(t){if(!t.initialized){t.initialized=!0;try{n(N,t),t.supported=!0}catch(t){E("Module '"+e+"' failed to load: "+T(t)),t.stack&&E(t.stack)}}}));return R[e]=r,r}function P(){}N.addShimListener=function(e){A.push(e)},v&&(N.shim=N.createMissingNativeApi=function(e){e=e||window,O();for(var t=0,n=A.length;t<n;++t)A[t](e)},D(N,"createMissingNativeApi","shim")),x.prototype={init:function(){for(var e,t,n=this.dependencies||[],r=0,o=n.length;r<o;++r){if(t=n[r],!((e=R[t])&&e instanceof x))throw new Error("required module '"+t+"' not found");if(e.init(),!e.supported)throw new Error("required module '"+t+"' not supported")}this.initializer(this)},fail:function(e){throw this.initialized=!0,this.supported=!1,new Error(e)},warn:function(e){N.warn("Module "+this.name+": "+e)},deprecationNotice:function(e,t){N.warn("DEPRECATED: "+e+" in module "+this.name+" is deprecated. Please use "+t+" instead")},createError:function(e){return new Error("Error in Rangy "+this.name+" module: "+e)}},N.createModule=function(e){var t,n;2==arguments.length?(t=arguments[1],n=[]):(t=arguments[2],n=arguments[1]);var r=b(e,n,t);N.initialized&&N.supported&&r.init()},N.createCoreModule=function(e,t,n){b(e,t,n)},N.RangePrototype=P,N.rangePrototype=new P,N.selectionPrototype=new function(){},N.createCoreModule("DomUtil",[],(function(e,t){var n="undefined",r=e.util,o=r.getBody;r.areHostMethods(document,["createDocumentFragment","createElement","createTextNode"])||t.fail("document missing a Node creation method"),r.isHostMethod(document,"getElementsByTagName")||t.fail("document missing getElementsByTagName method");var i=document.createElement("div");r.areHostMethods(i,["insertBefore","appendChild","cloneNode"]||!r.areHostObjects(i,["previousSibling","nextSibling","childNodes","parentNode"]))||t.fail("Incomplete Element implementation"),r.isHostProperty(i,"innerHTML")||t.fail("Element is missing innerHTML property");var a=document.createTextNode("test");r.areHostMethods(a,["splitText","deleteData","insertData","appendData","cloneNode"]||!r.areHostObjects(i,["previousSibling","nextSibling","childNodes","parentNode"])||!r.areHostProperties(a,["data"]))||t.fail("Incomplete Text Node implementation");var s=function(e,t){for(var n=e.length;n--;)if(e[n]===t)return!0;return!1};function c(e){for(var t=0;e=e.previousSibling;)++t;return t}function d(e,t){var n,r=[];for(n=e;n;n=n.parentNode)r.push(n);for(n=t;n;n=n.parentNode)if(s(r,n))return n;return null}function f(e,t,n){for(var r=n?t:t.parentNode;r;){if(r===e)return!0;r=r.parentNode}return!1}function u(e,t,n){for(var r,o=n?e:e.parentNode;o;){if((r=o.parentNode)===t)return o;o=r}return null}function l(e){var t=e.nodeType;return 3==t||4==t||8==t}function h(e,t){var n=t.nextSibling,r=t.parentNode;return n?r.insertBefore(e,n):r.appendChild(e),e}function g(e){if(9==e.nodeType)return e;if(typeof e.ownerDocument!=n)return e.ownerDocument;if(typeof e.document!=n)return e.document;if(e.parentNode)return g(e.parentNode);throw t.createError("getDocument: no document found for node")}function p(e){var r=g(e);if(typeof r.defaultView!=n)return r.defaultView;if(typeof r.parentWindow!=n)return r.parentWindow;throw t.createError("Cannot get a window object for node")}function m(e){if(typeof e.contentDocument!=n)return e.contentDocument;if(typeof e.contentWindow!=n)return e.contentWindow.document;throw t.createError("getIframeDocument: No Document object found for iframe element")}function R(e){return e&&r.isHostMethod(e,"setTimeout")&&r.isHostObject(e,"document")}var v,C=!1;function N(e){try{return e.parentNode,!1}catch(e){return!0}}function E(e){if(!e)return"[No node]";if(C&&N(e))return"[Broken node]";if(l(e))return'"'+e.data+'"';if(1==e.nodeType){var t=e.id?' id="'+e.id+'"':"";return"<"+e.nodeName+t+">[index:"+c(e)+",length:"+e.childNodes.length+"]["+(e.innerHTML||"[innerHTML not supported]").slice(0,25)+"]"}return e.nodeName}function S(e){this.root=e,this._next=e}function y(e,t){this.node=e,this.offset=t}function w(e){this.code=this[e],this.codeName=e,this.message="DOMException: "+this.codeName}!function(){var t=document.createElement("b");t.innerHTML="1";var n=t.firstChild;t.innerHTML="<br />",C=N(n),e.features.crashyTextNodes=C}(),typeof window.getComputedStyle!=n?v=function(e,t){return p(e).getComputedStyle(e,null)[t]}:typeof document.documentElement.currentStyle!=n?v=function(e,t){return e.currentStyle?e.currentStyle[t]:""}:t.fail("No means of obtaining computed style properties found"),S.prototype={_current:null,hasNext:function(){return!!this._next},next:function(){var e,t,n=this._current=this._next;if(this._current)if(e=n.firstChild)this._next=e;else{for(t=null;n!==this.root&&!(t=n.nextSibling);)n=n.parentNode;this._next=t}return this._current},detach:function(){this._current=this._next=this.root=null}},y.prototype={equals:function(e){return!!e&&this.node===e.node&&this.offset==e.offset},inspect:function(){return"[DomPosition("+E(this.node)+":"+this.offset+")]"},toString:function(){return this.inspect()}},w.prototype={INDEX_SIZE_ERR:1,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INVALID_STATE_ERR:11,INVALID_NODE_TYPE_ERR:24},w.prototype.toString=function(){return this.message},e.dom={arrayContains:s,isHtmlNamespace:function(e){var t;return typeof e.namespaceURI==n||null===(t=e.namespaceURI)||"http://www.w3.org/1999/xhtml"==t},parentElement:function(e){var t=e.parentNode;return 1==t.nodeType?t:null},getNodeIndex:c,getNodeLength:function(e){switch(e.nodeType){case 7:case 10:return 0;case 3:case 8:return e.length;default:return e.childNodes.length}},getCommonAncestor:d,isAncestorOf:f,isOrIsAncestorOf:function(e,t){return f(e,t,!0)},getClosestAncestorIn:u,isCharacterDataNode:l,isTextOrCommentNode:function(e){if(!e)return!1;var t=e.nodeType;return 3==t||8==t},insertAfter:h,splitDataNode:function(e,t,n){var r=e.cloneNode(!1);if(r.deleteData(0,t),e.deleteData(t,e.length-t),h(r,e),n)for(var o,i=0;o=n[i++];)o.node==e&&o.offset>t?(o.node=r,o.offset-=t):o.node==e.parentNode&&o.offset>c(e)&&++o.offset;return r},getDocument:g,getWindow:p,getIframeWindow:function(e){if(typeof e.contentWindow!=n)return e.contentWindow;if(typeof e.contentDocument!=n)return e.contentDocument.defaultView;throw t.createError("getIframeWindow: No Window object found for iframe element")},getIframeDocument:m,getBody:o,isWindow:R,getContentDocument:function(e,t,n){var o;if(e?r.isHostProperty(e,"nodeType")?o=1==e.nodeType&&"iframe"==e.tagName.toLowerCase()?m(e):g(e):R(e)&&(o=e.document):o=document,!o)throw t.createError(n+"(): Parameter must be a Window object or DOM node");return o},getRootContainer:function(e){for(var t;t=e.parentNode;)e=t;return e},comparePoints:function(e,n,r,o){var i,a,s,f,l;if(e==r)return n===o?0:n<o?-1:1;if(i=u(r,e,!0))return n<=c(i)?-1:1;if(i=u(e,r,!0))return c(i)<o?-1:1;if(!(a=d(e,r)))throw new Error("comparePoints error: nodes have no common ancestor");if((s=e===a?a:u(e,a,!0))===(f=r===a?a:u(r,a,!0)))throw t.createError("comparePoints got to case 4 and childA and childB are the same!");for(l=a.firstChild;l;){if(l===s)return-1;if(l===f)return 1;l=l.nextSibling}},isBrokenNode:N,inspectNode:E,getComputedStyleProperty:v,createTestElement:function(e,t,n){var r=o(e),i=e.createElement("div");i.contentEditable=""+!!n,t&&(i.innerHTML=t);var a=r.firstChild;return a?r.insertBefore(i,a):r.appendChild(i),i},removeNode:function(e){return e.parentNode.removeChild(e)},fragmentFromNodeChildren:function(e){for(var t,n=g(e).createDocumentFragment();t=e.firstChild;)n.appendChild(t);return n},createIterator:function(e){return new S(e)},DomPosition:y},e.DOMException=w})),N.createCoreModule("DomRange",["DomUtil"],(function(e,t){var n=e.dom,r=e.util,o=n.DomPosition,i=e.DOMException,a=n.isCharacterDataNode,s=n.getNodeIndex,c=n.isOrIsAncestorOf,d=n.getDocument,f=n.comparePoints,u=n.splitDataNode,l=n.getClosestAncestorIn,h=n.getNodeLength,g=n.arrayContains,p=n.getRootContainer,m=e.features.crashyTextNodes,R=n.removeNode;function v(e,t){return 3!=e.nodeType&&(c(e,t.startContainer)||c(e,t.endContainer))}function C(e){return e.document||d(e.startContainer)}function N(e){return new o(e.parentNode,s(e))}function E(e){return new o(e.parentNode,s(e)+1)}function S(e,t,r){var o=11==e.nodeType?e.firstChild:e;return a(t)?r==t.length?n.insertAfter(e,t):t.parentNode.insertBefore(e,0==r?t:u(t,r)):r>=t.childNodes.length?t.appendChild(e):t.insertBefore(e,t.childNodes[r]),o}function y(e,t,n){if(Q(e),Q(t),C(t)!=C(e))throw new i("WRONG_DOCUMENT_ERR");var r=f(e.startContainer,e.startOffset,t.endContainer,t.endOffset),o=f(e.endContainer,e.endOffset,t.startContainer,t.startOffset);return n?r<=0&&o>=0:r<0&&o>0}function w(e){for(var t,n,r,o=C(e.range).createDocumentFragment();n=e.next();){if(t=e.isPartiallySelectedSubtree(),n=n.cloneNode(!t),t&&(r=e.getSubtreeIterator(),n.appendChild(w(r)),r.detach()),10==n.nodeType)throw new i("HIERARCHY_REQUEST_ERR");o.appendChild(n)}return o}function T(e,t,r){var o,i,a,s;for(r=r||{stop:!1};a=e.next();)if(e.isPartiallySelectedSubtree()){if(!1===t(a))return void(r.stop=!0);if(T(s=e.getSubtreeIterator(),t,r),s.detach(),r.stop)return}else for(o=n.createIterator(a);i=o.next();)if(!1===t(i))return void(r.stop=!0)}function O(e){for(var t;e.next();)e.isPartiallySelectedSubtree()?(O(t=e.getSubtreeIterator()),t.detach()):e.remove()}function _(e){for(var t,n,r=C(e.range).createDocumentFragment();t=e.next();){if(e.isPartiallySelectedSubtree()?(t=t.cloneNode(!1),n=e.getSubtreeIterator(),t.appendChild(_(n)),n.detach()):e.remove(),10==t.nodeType)throw new i("HIERARCHY_REQUEST_ERR");r.appendChild(t)}return r}function D(e){return"["+(void 0===e.getName?"Range":e.getName())+"("+n.inspectNode(e.startContainer)+":"+e.startOffset+", "+n.inspectNode(e.endContainer)+":"+e.endOffset+")]"}function A(e,t){if(this.range=e,this.clonePartiallySelectedTextNodes=t,!e.collapsed){this.sc=e.startContainer,this.so=e.startOffset,this.ec=e.endContainer,this.eo=e.endOffset;var n=e.commonAncestorContainer;this.sc===this.ec&&a(this.sc)?(this.isSingleCharacterDataNode=!0,this._first=this._last=this._next=this.sc):(this._first=this._next=this.sc!==n||a(this.sc)?l(this.sc,n,!0):this.sc.childNodes[this.so],this._last=this.ec!==n||a(this.ec)?l(this.ec,n,!0):this.ec.childNodes[this.eo-1])}}A.prototype={_current:null,_next:null,_first:null,_last:null,isSingleCharacterDataNode:!1,reset:function(){this._current=null,this._next=this._first},hasNext:function(){return!!this._next},next:function(){var e=this._current=this._next;return e&&(this._next=e!==this._last?e.nextSibling:null,a(e)&&this.clonePartiallySelectedTextNodes&&(e===this.ec&&(e=e.cloneNode(!0)).deleteData(this.eo,e.length-this.eo),this._current===this.sc&&(e=e.cloneNode(!0)).deleteData(0,this.so))),e},remove:function(){var e,t,n=this._current;!a(n)||n!==this.sc&&n!==this.ec?n.parentNode&&R(n):(e=n===this.sc?this.so:0)!=(t=n===this.ec?this.eo:n.length)&&n.deleteData(e,t-e)},isPartiallySelectedSubtree:function(){return v(this._current,this.range)},getSubtreeIterator:function(){var e;if(this.isSingleCharacterDataNode)(e=this.range.cloneRange()).collapse(!1);else{e=new ie(C(this.range));var t=this._current,n=t,r=0,o=t,i=h(t);c(t,this.sc)&&(n=this.sc,r=this.so),c(t,this.ec)&&(o=this.ec,i=this.eo),oe(e,n,r,o,i)}return new A(e,this.clonePartiallySelectedTextNodes)},detach:function(){this.range=this._current=this._next=this._first=this._last=this.sc=this.so=this.ec=this.eo=null}};var x=[1,3,4,5,7,8,10],b=[2,9,11],P=[1,3,4,5,7,8,10,11],I=[1,3,4,5,7,8];function B(e){return function(t,n){for(var r,o=n?t:t.parentNode;o;){if(r=o.nodeType,g(e,r))return o;o=o.parentNode}return null}}var H=B([9,11]),M=B([5,6,10,12]),k=B([6,10,12]),L=B([1]);function W(e,t){if(k(e,t))throw new i("INVALID_NODE_TYPE_ERR")}function F(e,t){if(!g(t,e.nodeType))throw new i("INVALID_NODE_TYPE_ERR")}function j(e,t){if(t<0||t>(a(e)?e.length:e.childNodes.length))throw new i("INDEX_SIZE_ERR")}function z(e,t){if(H(e,!0)!==H(t,!0))throw new i("WRONG_DOCUMENT_ERR")}function U(e){if(M(e,!0))throw new i("NO_MODIFICATION_ALLOWED_ERR")}function V(e,t){if(!e)throw new i(t)}function q(e,t){return t<=(a(e)?e.length:e.childNodes.length)}function Y(e){return!!e.startContainer&&!!e.endContainer&&!(m&&(n.isBrokenNode(e.startContainer)||n.isBrokenNode(e.endContainer)))&&p(e.startContainer)==p(e.endContainer)&&q(e.startContainer,e.startOffset)&&q(e.endContainer,e.endOffset)}function Q(e){if(!Y(e))throw new Error("Range error: Range is not valid. This usually happens after DOM mutation. Range: ("+e.inspect()+")")}var G=document.createElement("style"),X=!1;try{G.innerHTML="<b>x</b>",X=3==G.firstChild.nodeType}catch(e){}e.features.htmlParsingConforms=X;var Z=X?function(e){var t=this.startContainer,r=d(t);if(!t)throw new i("INVALID_STATE_ERR");var o=null;return 1==t.nodeType?o=t:a(t)&&(o=n.parentElement(t)),(o=null===o||"HTML"==o.nodeName&&n.isHtmlNamespace(d(o).documentElement)&&n.isHtmlNamespace(o)?r.createElement("body"):o.cloneNode(!1)).innerHTML=e,n.fragmentFromNodeChildren(o)}:function(e){var t=C(this).createElement("body");return t.innerHTML=e,n.fragmentFromNodeChildren(t)};function $(e,t){Q(e);var n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset,c=n===o;a(o)&&i>0&&i<o.length&&u(o,i,t),a(n)&&r>0&&r<n.length&&(n=u(n,r,t),c?(i-=r,o=n):o==n.parentNode&&i>=s(n)&&i++,r=0),e.setStartAndEnd(n,r,o,i)}function J(e){Q(e);var t=e.commonAncestorContainer.parentNode.cloneNode(!1);return t.appendChild(e.cloneContents()),t.innerHTML}var K=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"];function ee(e){e.START_TO_START=0,e.START_TO_END=1,e.END_TO_END=2,e.END_TO_START=3,e.NODE_BEFORE=0,e.NODE_AFTER=1,e.NODE_BEFORE_AND_AFTER=2,e.NODE_INSIDE=3}function te(e){ee(e),ee(e.prototype)}function ne(e,t){return function(){Q(this);var n,r=this.startContainer,o=this.startOffset,i=this.commonAncestorContainer,a=new A(this,!0);r!==i&&(r=(n=E(l(r,i,!0))).node,o=n.offset),T(a,U),a.reset();var s=e(a);return a.detach(),t(this,r,o,r,o),s}}function re(t,n){function o(e,t){return function(n){F(n,x),F(p(n),b);var r=(e?N:E)(n);(t?i:c)(this,r.node,r.offset)}}function i(e,t,r){var o=e.endContainer,i=e.endOffset;t===e.startContainer&&r===e.startOffset||(p(t)==p(o)&&1!=f(t,r,o,i)||(o=t,i=r),n(e,t,r,o,i))}function c(e,t,r){var o=e.startContainer,i=e.startOffset;t===e.endContainer&&r===e.endOffset||(p(t)==p(o)&&-1!=f(t,r,o,i)||(o=t,i=r),n(e,o,i,t,r))}var d=function(){};d.prototype=e.rangePrototype,t.prototype=new d,r.extend(t.prototype,{setStart:function(e,t){W(e,!0),j(e,t),i(this,e,t)},setEnd:function(e,t){W(e,!0),j(e,t),c(this,e,t)},setStartAndEnd:function(){var e=arguments,t=e[0],r=e[1],o=t,i=r;switch(e.length){case 3:i=e[2];break;case 4:o=e[2],i=e[3]}W(t,!0),j(t,r),W(o,!0),j(o,i),n(this,t,r,o,i)},setBoundary:function(e,t,n){this["set"+(n?"Start":"End")](e,t)},setStartBefore:o(!0,!0),setStartAfter:o(!1,!0),setEndBefore:o(!0,!1),setEndAfter:o(!1,!1),collapse:function(e){Q(this),e?n(this,this.startContainer,this.startOffset,this.startContainer,this.startOffset):n(this,this.endContainer,this.endOffset,this.endContainer,this.endOffset)},selectNodeContents:function(e){W(e,!0),n(this,e,0,e,h(e))},selectNode:function(e){W(e,!1),F(e,x);var t=N(e),r=E(e);n(this,t.node,t.offset,r.node,r.offset)},extractContents:ne(_,n),deleteContents:ne(O,n),canSurroundContents:function(){Q(this),U(this.startContainer),U(this.endContainer);var e=new A(this,!0),t=e._first&&v(e._first,this)||e._last&&v(e._last,this);return e.detach(),!t},splitBoundaries:function(){$(this)},splitBoundariesPreservingPositions:function(e){$(this,e)},normalizeBoundaries:function(){Q(this);var e,t=this.startContainer,r=this.startOffset,o=this.endContainer,i=this.endOffset,c=function(e){var t=e.nextSibling;t&&t.nodeType==e.nodeType&&(o=e,i=e.length,e.appendData(t.data),R(t))},d=function(e){var n=e.previousSibling;if(n&&n.nodeType==e.nodeType){t=e;var a=e.length;if(r=n.length,e.insertData(0,n.data),R(n),t==o)i+=r,o=t;else if(o==e.parentNode){var c=s(e);i==c?(o=e,i=a):i>c&&i--}}},f=!0;if(a(o))i==o.length?c(o):0==i&&(e=o.previousSibling)&&e.nodeType==o.nodeType&&(i=e.length,t==o&&(f=!1),e.appendData(o.data),R(o),o=e);else{if(i>0){var u=o.childNodes[i-1];u&&a(u)&&c(u)}f=!this.collapsed}if(f){if(a(t))0==r?d(t):r==t.length&&(e=t.nextSibling)&&e.nodeType==t.nodeType&&(o==e&&(o=t,i+=t.length),t.appendData(e.data),R(e));else if(r<t.childNodes.length){var l=t.childNodes[r];l&&a(l)&&d(l)}}else t=o,r=i;n(this,t,r,o,i)},collapseToPoint:function(e,t){W(e,!0),j(e,t),this.setStartAndEnd(e,t)},parentElement:function(){return Q(this),this.commonAncestorContainer?L(this.commonAncestorContainer,!0):null}}),te(t)}function oe(e,t,r,o,i){e.startContainer=t,e.startOffset=r,e.endContainer=o,e.endOffset=i,e.document=n.getDocument(t),function(e){e.collapsed=e.startContainer===e.endContainer&&e.startOffset===e.endOffset,e.commonAncestorContainer=e.collapsed?e.startContainer:n.getCommonAncestor(e.startContainer,e.endContainer)}(e)}function ie(e){oe(this,e,0,e,0)}r.extend(e.rangePrototype,{compareBoundaryPoints:function(e,t){var n,r,o,i;Q(this),z(this.startContainer,t.startContainer);var a=3==e||0==e?"start":"end",s=1==e||0==e?"start":"end";return n=this[a+"Container"],r=this[a+"Offset"],o=t[s+"Container"],i=t[s+"Offset"],f(n,r,o,i)},insertNode:function(e){if(Q(this),F(e,P),U(this.startContainer),c(e,this.startContainer))throw new i("HIERARCHY_REQUEST_ERR");var t=S(e,this.startContainer,this.startOffset);this.setStartBefore(t)},cloneContents:function(){var e,t;if(Q(this),this.collapsed)return C(this).createDocumentFragment();if(this.startContainer===this.endContainer&&a(this.startContainer))return(e=this.startContainer.cloneNode(!0)).data=e.data.slice(this.startOffset,this.endOffset),(t=C(this).createDocumentFragment()).appendChild(e),t;var n=new A(this,!0);return e=w(n),n.detach(),e},canSurroundContents:function(){Q(this),U(this.startContainer),U(this.endContainer);var e=new A(this,!0),t=e._first&&v(e._first,this)||e._last&&v(e._last,this);return e.detach(),!t},surroundContents:function(e){if(F(e,I),!this.canSurroundContents())throw new i("INVALID_STATE_ERR");var t=this.extractContents();if(e.hasChildNodes())for(;e.lastChild;)e.removeChild(e.lastChild);S(e,this.startContainer,this.startOffset),e.appendChild(t),this.selectNode(e)},cloneRange:function(){Q(this);for(var e,t=new ie(C(this)),n=K.length;n--;)t[e=K[n]]=this[e];return t},toString:function(){Q(this);var e=this.startContainer;if(e===this.endContainer&&a(e))return 3==e.nodeType||4==e.nodeType?e.data.slice(this.startOffset,this.endOffset):"";var t=[],n=new A(this,!0);return T(n,(function(e){3!=e.nodeType&&4!=e.nodeType||t.push(e.data)})),n.detach(),t.join("")},compareNode:function(e){Q(this);var t=e.parentNode,n=s(e);if(!t)throw new i("NOT_FOUND_ERR");var r=this.comparePoint(t,n),o=this.comparePoint(t,n+1);return r<0?o>0?2:0:o>0?1:3},comparePoint:function(e,t){return Q(this),V(e,"HIERARCHY_REQUEST_ERR"),z(e,this.startContainer),f(e,t,this.startContainer,this.startOffset)<0?-1:f(e,t,this.endContainer,this.endOffset)>0?1:0},createContextualFragment:Z,toHtml:function(){return J(this)},intersectsNode:function(e,t){if(Q(this),p(e)!=p(this.startContainer))return!1;var n=e.parentNode,r=s(e);if(!n)return!0;var o=f(n,r,this.endContainer,this.endOffset),i=f(n,r+1,this.startContainer,this.startOffset);return t?o<=0&&i>=0:o<0&&i>0},isPointInRange:function(e,t){return Q(this),V(e,"HIERARCHY_REQUEST_ERR"),z(e,this.startContainer),f(e,t,this.startContainer,this.startOffset)>=0&&f(e,t,this.endContainer,this.endOffset)<=0},intersectsRange:function(e){return y(this,e,!1)},intersectsOrTouchesRange:function(e){return y(this,e,!0)},intersection:function(e){if(this.intersectsRange(e)){var t=f(this.startContainer,this.startOffset,e.startContainer,e.startOffset),n=f(this.endContainer,this.endOffset,e.endContainer,e.endOffset),r=this.cloneRange();return-1==t&&r.setStart(e.startContainer,e.startOffset),1==n&&r.setEnd(e.endContainer,e.endOffset),r}return null},union:function(e){if(this.intersectsOrTouchesRange(e)){var t=this.cloneRange();return-1==f(e.startContainer,e.startOffset,this.startContainer,this.startOffset)&&t.setStart(e.startContainer,e.startOffset),1==f(e.endContainer,e.endOffset,this.endContainer,this.endOffset)&&t.setEnd(e.endContainer,e.endOffset),t}throw new i("Ranges do not intersect")},containsNode:function(e,t){return t?this.intersectsNode(e,!1):3==this.compareNode(e)},containsNodeContents:function(e){return this.comparePoint(e,0)>=0&&this.comparePoint(e,h(e))<=0},containsRange:function(e){var t=this.intersection(e);return null!==t&&e.equals(t)},containsNodeText:function(e){var t=this.cloneRange();t.selectNode(e);var n=t.getNodes([3]);if(n.length>0){t.setStart(n[0],0);var r=n.pop();return t.setEnd(r,r.length),this.containsRange(t)}return this.containsNodeContents(e)},getNodes:function(e,t){return Q(this),function(e,t,n){var r,o=!(!t||!t.length),i=!!n;o&&(r=new RegExp("^("+t.join("|")+")$"));var s=[];return T(new A(e,!1),(function(t){if((!o||r.test(t.nodeType))&&(!i||n(t))){var c=e.startContainer;if(t!=c||!a(c)||e.startOffset!=c.length){var d=e.endContainer;t==d&&a(d)&&0==e.endOffset||s.push(t)}}})),s}(this,e,t)},getDocument:function(){return C(this)},collapseBefore:function(e){this.setEndBefore(e),this.collapse(!1)},collapseAfter:function(e){this.setStartAfter(e),this.collapse(!0)},getBookmark:function(t){var r=C(this),o=e.createRange(r);t=t||n.getBody(r),o.selectNodeContents(t);var i=this.intersection(o),a=0,s=0;return i&&(o.setEnd(i.startContainer,i.startOffset),s=(a=o.toString().length)+i.toString().length),{start:a,end:s,containerNode:t}},moveToBookmark:function(e){var t=e.containerNode,n=0;this.setStart(t,0),this.collapse(!0);for(var r,o,i,a,s=[t],c=!1,d=!1;!d&&(r=s.pop());)if(3==r.nodeType)o=n+r.length,!c&&e.start>=n&&e.start<=o&&(this.setStart(r,e.start-n),c=!0),c&&e.end>=n&&e.end<=o&&(this.setEnd(r,e.end-n),d=!0),n=o;else for(i=(a=r.childNodes).length;i--;)s.push(a[i])},getName:function(){return"DomRange"},equals:function(e){return ie.rangesEqual(this,e)},isValid:function(){return Y(this)},inspect:function(){return D(this)},detach:function(){}}),re(ie,oe),r.extend(ie,{rangeProperties:K,RangeIterator:A,copyComparisonConstants:te,createPrototypeRange:re,inspect:D,toHtml:J,getRangeDocument:C,rangesEqual:function(e,t){return e.startContainer===t.startContainer&&e.startOffset===t.startOffset&&e.endContainer===t.endContainer&&e.endOffset===t.endOffset}}),e.DomRange=ie})),N.createCoreModule("WrappedRange",["DomRange"],(function(e,t){var n,r,o=e.dom,i=e.util,a=o.DomPosition,s=e.DomRange,c=o.getBody,d=o.getContentDocument,f=o.isCharacterDataNode;if(e.features.implementsDomRange&&function(){var r,a,f=s.rangeProperties;function u(e){for(var t,n=f.length;n--;)e[t=f[n]]=e.nativeRange[t];e.collapsed=e.startContainer===e.endContainer&&e.startOffset===e.endOffset}n=function(e){if(!e)throw t.createError("WrappedRange: Range must be specified");this.nativeRange=e,u(this)},s.createPrototypeRange(n,(function(e,t,n,r,o){var i=e.startContainer!==t||e.startOffset!=n,a=e.endContainer!==r||e.endOffset!=o,s=!e.equals(e.nativeRange);(i||a||s)&&(e.setEnd(r,o),e.setStart(t,n))})),(r=n.prototype).selectNode=function(e){this.nativeRange.selectNode(e),u(this)},r.cloneContents=function(){return this.nativeRange.cloneContents()},r.surroundContents=function(e){this.nativeRange.surroundContents(e),u(this)},r.collapse=function(e){this.nativeRange.collapse(e),u(this)},r.cloneRange=function(){return new n(this.nativeRange.cloneRange())},r.refresh=function(){u(this)},r.toString=function(){return this.nativeRange.toString()};var l=document.createTextNode("test");c(document).appendChild(l);var h=document.createRange();h.setStart(l,0),h.setEnd(l,0);try{h.setStart(l,1),r.setStart=function(e,t){this.nativeRange.setStart(e,t),u(this)},r.setEnd=function(e,t){this.nativeRange.setEnd(e,t),u(this)},a=function(e){return function(t){this.nativeRange[e](t),u(this)}}}catch(e){r.setStart=function(e,t){try{this.nativeRange.setStart(e,t)}catch(n){this.nativeRange.setEnd(e,t),this.nativeRange.setStart(e,t)}u(this)},r.setEnd=function(e,t){try{this.nativeRange.setEnd(e,t)}catch(n){this.nativeRange.setStart(e,t),this.nativeRange.setEnd(e,t)}u(this)},a=function(e,t){return function(n){try{this.nativeRange[e](n)}catch(r){this.nativeRange[t](n),this.nativeRange[e](n)}u(this)}}}r.setStartBefore=a("setStartBefore","setEndBefore"),r.setStartAfter=a("setStartAfter","setEndAfter"),r.setEndBefore=a("setEndBefore","setStartBefore"),r.setEndAfter=a("setEndAfter","setStartAfter"),r.selectNodeContents=function(e){this.setStartAndEnd(e,0,o.getNodeLength(e))},h.selectNodeContents(l),h.setEnd(l,3);var g=document.createRange();g.selectNodeContents(l),g.setEnd(l,4),g.setStart(l,2),-1==h.compareBoundaryPoints(h.START_TO_END,g)&&1==h.compareBoundaryPoints(h.END_TO_START,g)?r.compareBoundaryPoints=function(e,t){return e==(t=t.nativeRange||t).START_TO_END?e=t.END_TO_START:e==t.END_TO_START&&(e=t.START_TO_END),this.nativeRange.compareBoundaryPoints(e,t)}:r.compareBoundaryPoints=function(e,t){return this.nativeRange.compareBoundaryPoints(e,t.nativeRange||t)};var p=document.createElement("div");p.innerHTML="123";var m=p.firstChild,R=c(document);R.appendChild(p),h.setStart(m,1),h.setEnd(m,2),h.deleteContents(),"13"==m.data&&(r.deleteContents=function(){this.nativeRange.deleteContents(),u(this)},r.extractContents=function(){var e=this.nativeRange.extractContents();return u(this),e}),R.removeChild(p),R=null,i.isHostMethod(h,"createContextualFragment")&&(r.createContextualFragment=function(e){return this.nativeRange.createContextualFragment(e)}),c(document).removeChild(l),r.getName=function(){return"WrappedRange"},e.WrappedRange=n,e.createNativeRange=function(e){return(e=d(e,t,"createNativeRange")).createRange()}}(),e.features.implementsTextRange){var u=function(e,t,n,r,i){var s=e.duplicate();s.collapse(n);var c=s.parentElement();if(o.isOrIsAncestorOf(t,c)||(c=t),!c.canHaveHTML){var d=new a(c.parentNode,o.getNodeIndex(c));return{boundaryPosition:d,nodeInfo:{nodeIndex:d.offset,containerElement:d.node}}}var u=o.getDocument(c).createElement("span");u.parentNode&&o.removeNode(u);for(var l,h,g,p,m,R=n?"StartToStart":"StartToEnd",v=i&&i.containerElement==c?i.nodeIndex:0,C=c.childNodes.length,N=C,E=N;E==C?c.appendChild(u):c.insertBefore(u,c.childNodes[E]),s.moveToElementText(u),0!=(l=s.compareEndPoints(R,e))&&v!=N;){if(-1==l){if(N==v+1)break;v=E}else N=N==v+1?v:E;E=Math.floor((v+N)/2),c.removeChild(u)}if(m=u.nextSibling,-1==l&&m&&f(m)){var S;if(s.setEndPoint(n?"EndToStart":"EndToEnd",e),/[\r\n]/.test(m.data)){var y=s.duplicate(),w=y.text.replace(/\r\n/g,"\r").length;for(S=y.moveStart("character",w);-1==(l=y.compareEndPoints("StartToEnd",y));)S++,y.moveStart("character",1)}else S=s.text.length;p=new a(m,S)}else h=(r||!n)&&u.previousSibling,p=(g=(r||n)&&u.nextSibling)&&f(g)?new a(g,0):h&&f(h)?new a(h,h.data.length):new a(c,o.getNodeIndex(u));return o.removeNode(u),{boundaryPosition:p,nodeInfo:{nodeIndex:E,containerElement:c}}},l=function(e,t){var n,r,i,a,s=e.offset,d=o.getDocument(e.node),u=c(d).createTextRange(),l=f(e.node);return l?r=(n=e.node).parentNode:(n=s<(a=e.node.childNodes).length?a[s]:null,r=e.node),(i=d.createElement("span")).innerHTML="&#feff;",n?r.insertBefore(i,n):r.appendChild(i),u.moveToElementText(i),u.collapse(!t),r.removeChild(i),l&&u[t?"moveStart":"moveEnd"]("character",s),u};((r=function(e){this.textRange=e,this.refresh()}).prototype=new s(document)).refresh=function(){var e,t,n,r,i=function(e){var t=e.parentElement(),n=e.duplicate();n.collapse(!0);var r=n.parentElement();(n=e.duplicate()).collapse(!1);var i=n.parentElement(),a=r==i?r:o.getCommonAncestor(r,i);return a==t?a:o.getCommonAncestor(t,a)}(this.textRange);0==(r=this.textRange).compareEndPoints("StartToEnd",r)?t=e=u(this.textRange,i,!0,!0).boundaryPosition:(e=(n=u(this.textRange,i,!0,!1)).boundaryPosition,t=u(this.textRange,i,!1,!1,n.nodeInfo).boundaryPosition),this.setStart(e.node,e.offset),this.setEnd(t.node,t.offset)},r.prototype.getName=function(){return"WrappedTextRange"},s.copyComparisonConstants(r);var h=function(e){if(e.collapsed)return l(new a(e.startContainer,e.startOffset),!0);var t=l(new a(e.startContainer,e.startOffset),!0),n=l(new a(e.endContainer,e.endOffset),!1),r=c(s.getRangeDocument(e)).createTextRange();return r.setEndPoint("StartToStart",t),r.setEndPoint("EndToEnd",n),r};if(r.rangeToTextRange=h,r.prototype.toTextRange=function(){return h(this)},e.WrappedTextRange=r,!e.features.implementsDomRange||e.config.preferTextRange){var g=Function("return this;")();void 0===g.Range&&(g.Range=r),e.createNativeRange=function(e){return e=d(e,t,"createNativeRange"),c(e).createTextRange()},e.WrappedRange=r}}e.createRange=function(n){return n=d(n,t,"createRange"),new e.WrappedRange(e.createNativeRange(n))},e.createRangyRange=function(e){return e=d(e,t,"createRangyRange"),new s(e)},i.createAliasForDeprecatedMethod(e,"createIframeRange","createRange"),i.createAliasForDeprecatedMethod(e,"createIframeRangyRange","createRangyRange"),e.addShimListener((function(t){var n=t.document;void 0===n.createRange&&(n.createRange=function(){return e.createRange(n)}),n=t=null}))})),N.createCoreModule("WrappedSelection",["DomRange","WrappedRange"],(function(e,t){e.config.checkSelectionRanges=!0;var n,r,o="boolean",i="number",a=e.dom,s=e.util,c=s.isHostMethod,d=e.DomRange,f=e.WrappedRange,u=e.DOMException,l=a.DomPosition,h=e.features,g="Control",p=a.getDocument,m=a.getBody,R=d.rangesEqual;function v(e){return"string"==typeof e?/^backward(s)?$/i.test(e):!!e}function C(e,n){if(e){if(a.isWindow(e))return e;if(e instanceof Q)return e.win;var r=a.getContentDocument(e,t,n);return a.getWindow(r)}return window}function N(e){return C(e,"getDocSelection").document.selection}function E(e){var t=!1;return e.anchorNode&&(t=1==a.comparePoints(e.anchorNode,e.anchorOffset,e.focusNode,e.focusOffset)),t}var S=c(window,"getSelection"),y=s.isHostObject(document,"selection");h.implementsWinGetSelection=S,h.implementsDocSelection=y;var w=y&&(!S||e.config.preferTextRange);if(w)n=N,e.isSelectionValid=function(e){var t=C(e,"isSelectionValid").document,n=t.selection;return"None"!=n.type||p(n.createRange().parentElement())==t};else{if(!S)return t.fail("Neither document.selection or window.getSelection() detected."),!1;n=function(e){return C(e,"getWinSelection").getSelection()},e.isSelectionValid=function(){return!0}}e.getNativeSelection=n;var T=n();if(!T)return t.fail("Native selection was null (possibly issue 138?)"),!1;var O=e.createNativeRange(document),_=m(document),D=s.areHostProperties(T,["anchorNode","focusNode","anchorOffset","focusOffset"]);h.selectionHasAnchorAndFocus=D;var A=c(T,"extend");h.selectionHasExtend=A;var x=c(T,"setBaseAndExtent");h.selectionHasSetBaseAndExtent=x;var b=typeof T.rangeCount==i;h.selectionHasRangeCount=b;var P=!1,I=!0,B=A?function(t,n){var r=d.getRangeDocument(n),o=e.createRange(r);o.collapseToPoint(n.endContainer,n.endOffset),t.addRange(j(o)),t.extend(n.startContainer,n.startOffset)}:null;s.areHostMethods(T,["addRange","getRangeAt","removeAllRanges"])&&typeof T.rangeCount==i&&h.implementsDomRange&&function(){var t=window.getSelection();if(t){for(var n=t.rangeCount,r=n>1,o=[],i=E(t),s=0;s<n;++s)o[s]=t.getRangeAt(s);var c=a.createTestElement(document,"",!1),d=c.appendChild(document.createTextNode("\xa0\xa0\xa0")),f=document.createRange();if(f.setStart(d,1),f.collapse(!0),t.removeAllRanges(),t.addRange(f),I=1==t.rangeCount,t.removeAllRanges(),!r){var u=window.navigator.appVersion.match(/Chrome\/(.*?) /);if(u&&parseInt(u[1])>=36)P=!1;else{var l=f.cloneRange();f.setStart(d,0),l.setEnd(d,3),l.setStart(d,2),t.addRange(f),t.addRange(l),P=2==t.rangeCount}}for(a.removeNode(c),t.removeAllRanges(),s=0;s<n;++s)0==s&&i?B?B(t,o[s]):(e.warn("Rangy initialization: original selection was backwards but selection has been restored forwards because the browser does not support Selection.extend"),t.addRange(o[s])):t.addRange(o[s])}}(),h.selectionSupportsMultipleRanges=P,h.collapsedNonEditableSelectionsSupported=I;var H,M,k=!1;function L(e,t,n){var r=n?"end":"start",o=n?"start":"end";e.anchorNode=t[r+"Container"],e.anchorOffset=t[r+"Offset"],e.focusNode=t[o+"Container"],e.focusOffset=t[o+"Offset"]}function W(e){e.anchorNode=e.focusNode=null,e.anchorOffset=e.focusOffset=0,e.rangeCount=0,e.isCollapsed=!0,e._ranges.length=0,F(e)}function F(e){e.type=0==e.rangeCount?"None":r(e)?"Caret":"Range"}function j(t){var n;return t instanceof d?((n=e.createNativeRange(t.getDocument())).setEnd(t.endContainer,t.endOffset),n.setStart(t.startContainer,t.startOffset)):t instanceof f?n=t.nativeRange:h.implementsDomRange&&t instanceof a.getWindow(t.startContainer).Range&&(n=t),n}function z(e){var n=e.getNodes();if(!function(e){if(!e.length||1!=e[0].nodeType)return!1;for(var t=1,n=e.length;t<n;++t)if(!a.isAncestorOf(e[0],e[t]))return!1;return!0}(n))throw t.createError("getSingleElementFromRange: range "+e.inspect()+" did not consist of a single element");return n[0]}function U(e){return!!e&&void 0!==e.text}function V(e,t){var n=new f(t);e._ranges=[n],L(e,n,!1),e.rangeCount=1,e.isCollapsed=n.collapsed,F(e)}function q(t){if(t._ranges.length=0,"None"==t.docSelection.type)W(t);else{var n=t.docSelection.createRange();if(U(n))V(t,n);else{t.rangeCount=n.length;for(var r,o=p(n.item(0)),i=0;i<t.rangeCount;++i)(r=e.createRange(o)).selectNode(n.item(i)),t._ranges.push(r);t.isCollapsed=1==t.rangeCount&&t._ranges[0].collapsed,L(t,t._ranges[t.rangeCount-1],!1),F(t)}}}function Y(e,n){for(var r=e.docSelection.createRange(),o=z(n),i=p(r.item(0)),a=m(i).createControlRange(),s=0,c=r.length;s<c;++s)a.add(r.item(s));try{a.add(o)}catch(e){throw t.createError("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)")}a.select(),q(e)}function Q(e,t,n){this.nativeSelection=e,this.docSelection=t,this._ranges=[],this.win=n,this.refresh()}function G(e){e.win=e.anchorNode=e.focusNode=e._ranges=null,e.rangeCount=e.anchorOffset=e.focusOffset=0,e.detached=!0,F(e)}_&&c(_,"createControlRange")&&(H=_.createControlRange(),s.areHostProperties(H,["item","add"])&&(k=!0)),h.implementsControlRange=k,r=D?function(e){return e.anchorNode===e.focusNode&&e.anchorOffset===e.focusOffset}:function(e){return!!e.rangeCount&&e.getRangeAt(e.rangeCount-1).collapsed},c(T,"getRangeAt")?M=function(e,t){try{return e.getRangeAt(t)}catch(e){return null}}:D&&(M=function(t){var n=p(t.anchorNode),r=e.createRange(n);return r.setStartAndEnd(t.anchorNode,t.anchorOffset,t.focusNode,t.focusOffset),r.collapsed!==this.isCollapsed&&r.setStartAndEnd(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset),r}),Q.prototype=e.selectionPrototype;var X=[];function Z(e,t){for(var n,r,o=X.length;o--;)if(r=(n=X[o]).selection,"deleteAll"==t)G(r);else if(n.win==e)return"delete"==t?(X.splice(o,1),!0):r;return"deleteAll"==t&&(X.length=0),null}var $=function(e){if(e&&e instanceof Q)return e.refresh(),e;var t=Z(e=C(e,"getNativeSelection")),r=n(e),o=y?N(e):null;return t?(t.nativeSelection=r,t.docSelection=o,t.refresh()):(t=new Q(r,o,e),X.push({win:e,selection:t})),t};e.getSelection=$,s.createAliasForDeprecatedMethod(e,"getIframeSelection","getSelection");var J,K=Q.prototype;function ee(e,n){for(var r,o=p(n[0].startContainer),i=m(o).createControlRange(),a=0,s=n.length;a<s;++a){r=z(n[a]);try{i.add(r)}catch(e){throw t.createError("setRanges(): Element within one of the specified Ranges could not be added to control selection (does it have layout?)")}}i.select(),q(e)}if(!w&&D&&s.areHostMethods(T,["removeAllRanges","addRange"])){K.removeAllRanges=function(){this.nativeSelection.removeAllRanges(),W(this)};var te=function(e,t){B(e.nativeSelection,t),e.refresh()};K.addRange=b?function(t,n){if(k&&y&&this.docSelection.type==g)Y(this,t);else if(v(n)&&A)te(this,t);else{var o;P?o=this.rangeCount:(this.removeAllRanges(),o=0);var i=j(t).cloneRange();try{this.nativeSelection.addRange(i)}catch(e){}if(this.rangeCount=this.nativeSelection.rangeCount,this.rangeCount==o+1){if(e.config.checkSelectionRanges){var a=M(this.nativeSelection,this.rangeCount-1);a&&!R(a,t)&&(t=new f(a))}this._ranges[this.rangeCount-1]=t,L(this,t,ne(this.nativeSelection)),this.isCollapsed=r(this),F(this)}else this.refresh()}}:function(e,t){v(t)&&A?te(this,e):(this.nativeSelection.addRange(j(e)),this.refresh())},K.setRanges=function(e){if(k&&y&&e.length>1)ee(this,e);else{this.removeAllRanges();for(var t=0,n=e.length;t<n;++t)this.addRange(e[t])}}}else{if(!(c(T,"empty")&&c(O,"select")&&k&&w))return t.fail("No means of selecting a Range or TextRange was found"),!1;K.removeAllRanges=function(){try{if(this.docSelection.empty(),"None"!=this.docSelection.type){var e;if(this.anchorNode)e=p(this.anchorNode);else if(this.docSelection.type==g){var t=this.docSelection.createRange();t.length&&(e=p(t.item(0)))}if(e)m(e).createTextRange().select(),this.docSelection.empty()}}catch(e){}W(this)},K.addRange=function(t){this.docSelection.type==g?Y(this,t):(e.WrappedTextRange.rangeToTextRange(t).select(),this._ranges[0]=t,this.rangeCount=1,this.isCollapsed=this._ranges[0].collapsed,L(this,t,!1),F(this))},K.setRanges=function(e){this.removeAllRanges();var t=e.length;t>1?ee(this,e):t&&this.addRange(e[0])}}if(K.getRangeAt=function(e){if(e<0||e>=this.rangeCount)throw new u("INDEX_SIZE_ERR");return this._ranges[e].cloneRange()},w)J=function(t){var n;e.isSelectionValid(t.win)?n=t.docSelection.createRange():(n=m(t.win.document).createTextRange()).collapse(!0),t.docSelection.type==g?q(t):U(n)?V(t,n):W(t)};else if(c(T,"getRangeAt")&&typeof T.rangeCount==i)J=function(t){if(k&&y&&t.docSelection.type==g)q(t);else if(t._ranges.length=t.rangeCount=t.nativeSelection.rangeCount,t.rangeCount){for(var n=0,o=t.rangeCount;n<o;++n)t._ranges[n]=new e.WrappedRange(t.nativeSelection.getRangeAt(n));L(t,t._ranges[t.rangeCount-1],ne(t.nativeSelection)),t.isCollapsed=r(t),F(t)}else W(t)};else{if(!D||typeof T.isCollapsed!=o||typeof O.collapsed!=o||!h.implementsDomRange)return t.fail("No means of obtaining a Range or TextRange from the user's selection was found"),!1;J=function(e){var t,n=e.nativeSelection;n.anchorNode?(t=M(n,0),e._ranges=[t],e.rangeCount=1,function(e){var t=e.nativeSelection;e.anchorNode=t.anchorNode,e.anchorOffset=t.anchorOffset,e.focusNode=t.focusNode,e.focusOffset=t.focusOffset}(e),e.isCollapsed=r(e),F(e)):W(e)}}K.refresh=function(e){var t=e?this._ranges.slice(0):null,n=this.anchorNode,r=this.anchorOffset;if(J(this),e){var o=t.length;if(o!=this._ranges.length)return!0;if(this.anchorNode!=n||this.anchorOffset!=r)return!0;for(;o--;)if(!R(t[o],this._ranges[o]))return!0;return!1}};var ne,re=function(e,t){var n=e.getAllRanges();e.removeAllRanges();for(var r=0,o=n.length;r<o;++r)R(t,n[r])||e.addRange(n[r]);e.rangeCount||W(e)};function oe(e,t){if(e.win.document!=p(t))throw new u("WRONG_DOCUMENT_ERR")}function ie(e,t){if(t<0||t>(a.isCharacterDataNode(e)?e.length:e.childNodes.length))throw new u("INDEX_SIZE_ERR")}function ae(t){return function(n,r){var o;this.rangeCount?(o=this.getRangeAt(0))["set"+(t?"Start":"End")](n,r):(o=e.createRange(this.win.document)).setStartAndEnd(n,r),this.setSingleRange(o,this.isBackward())}}function se(e){var t=[],n=new l(e.anchorNode,e.anchorOffset),r=new l(e.focusNode,e.focusOffset),o="function"==typeof e.getName?e.getName():"Selection";if(void 0!==e.rangeCount)for(var i=0,a=e.rangeCount;i<a;++i)t[i]=d.inspect(e.getRangeAt(i));return"["+o+"(Ranges: "+t.join(", ")+")(anchor: "+n.inspect()+", focus: "+r.inspect()+"]"}K.removeRange=k&&y?function(e){if(this.docSelection.type==g){for(var t=this.docSelection.createRange(),n=z(e),r=p(t.item(0)),o=m(r).createControlRange(),i=!1,a=0,s=t.length;a<s;++a)t.item(a)!==n||i?o.add(t.item(a)):i=!0;o.select(),q(this)}else re(this,e)}:function(e){re(this,e)},!w&&D&&h.implementsDomRange?(ne=E,K.isBackward=function(){return ne(this)}):ne=K.isBackward=function(){return!1},K.isBackwards=K.isBackward,K.toString=function(){for(var e=[],t=0,n=this.rangeCount;t<n;++t)e[t]=""+this._ranges[t];return e.join("")},K.collapse=function(t,n){oe(this,t);var r=e.createRange(t);r.collapseToPoint(t,n),this.setSingleRange(r),this.isCollapsed=!0},K.collapseToStart=function(){if(!this.rangeCount)throw new u("INVALID_STATE_ERR");var e=this._ranges[0];this.collapse(e.startContainer,e.startOffset)},K.collapseToEnd=function(){if(!this.rangeCount)throw new u("INVALID_STATE_ERR");var e=this._ranges[this.rangeCount-1];this.collapse(e.endContainer,e.endOffset)},K.selectAllChildren=function(t){oe(this,t);var n=e.createRange(t);n.selectNodeContents(t),this.setSingleRange(n)},x?K.setBaseAndExtent=function(e,t,n,r){this.nativeSelection.setBaseAndExtent(e,t,n,r),this.refresh()}:A&&(K.setBaseAndExtent=function(t,n,r,o){ie(t,n),ie(r,o),oe(this,t),oe(this,r);var i=e.createRange(node),s=-1==a.comparePoints(t,n,r,o);s?i.setStartAndEnd(r,o,t,n):i.setStartAndEnd(t,n,r,o),this.setSingleRange(i,s)}),K.deleteFromDocument=function(){if(k&&y&&this.docSelection.type==g){for(var e,t=this.docSelection.createRange();t.length;)e=t.item(0),t.remove(e),a.removeNode(e);this.refresh()}else if(this.rangeCount){var n=this.getAllRanges();if(n.length){this.removeAllRanges();for(var r=0,o=n.length;r<o;++r)n[r].deleteContents();this.addRange(n[o-1])}}},K.eachRange=function(e,t){for(var n=0,r=this._ranges.length;n<r;++n)if(e(this.getRangeAt(n)))return t},K.getAllRanges=function(){var e=[];return this.eachRange((function(t){e.push(t)})),e},K.setSingleRange=function(e,t){this.removeAllRanges(),this.addRange(e,t)},K.callMethodOnEachRange=function(e,t){var n=[];return this.eachRange((function(r){n.push(r[e].apply(r,t||[]))})),n},K.setStart=ae(!0),K.setEnd=ae(!1),e.rangePrototype.select=function(e){$(this.getDocument()).setSingleRange(this,e)},K.changeEachRange=function(e){var t=[],n=this.isBackward();this.eachRange((function(n){e(n),t.push(n)})),this.removeAllRanges(),n&&1==t.length?this.addRange(t[0],"backward"):this.setRanges(t)},K.containsNode=function(e,t){return this.eachRange((function(n){return n.containsNode(e,t)}),!0)||!1},K.getBookmark=function(e){return{backward:this.isBackward(),rangeBookmarks:this.callMethodOnEachRange("getBookmark",[e])}},K.moveToBookmark=function(t){for(var n,r,o=[],i=0;n=t.rangeBookmarks[i++];)(r=e.createRange(this.win)).moveToBookmark(n),o.push(r);t.backward?this.setSingleRange(o[0],"backward"):this.setRanges(o)},K.saveRanges=function(){return{backward:this.isBackward(),ranges:this.callMethodOnEachRange("cloneRange")}},K.restoreRanges=function(e){this.removeAllRanges();for(var t,n=0;t=e.ranges[n];++n)this.addRange(t,e.backward&&0==n)},K.toHtml=function(){var e=[];return this.eachRange((function(t){e.push(d.toHtml(t))})),e.join("")},h.implementsTextRange&&(K.getNativeTextRange=function(){var n;if(n=this.docSelection){var r=n.createRange();if(U(r))return r;throw t.createError("getNativeTextRange: selection is a control selection")}if(this.rangeCount>0)return e.WrappedTextRange.rangeToTextRange(this.getRangeAt(0));throw t.createError("getNativeTextRange: selection contains no range")}),K.getName=function(){return"WrappedSelection"},K.inspect=function(){return se(this)},K.detach=function(){Z(this.win,"delete"),G(this)},Q.detachAll=function(){Z(null,"deleteAll")},Q.inspect=se,Q.isDirectionBackward=v,e.Selection=Q,e.selectionPrototype=K,e.addShimListener((function(e){void 0===e.getSelection&&(e.getSelection=function(){return $(e)}),e=null}))}));var I=!1,B=function(e){I||(I=!0,!N.initialized&&N.config.autoInitialize&&O())};return v&&("complete"==document.readyState?B():(a(document,"addEventListener")&&document.addEventListener("DOMContentLoaded",B,!1),m(window,"load",B))),N}),this);