diff --git a/build/squire.js b/build/squire.js index bccfd56..448d828 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1 +1 @@ -/* Copyright © 2011-2012 by Neil Jenkins. Licensed under the MIT license. *//*global navigator, window */var UA=function(e){"use strict";var t=navigator.userAgent,n=!!e.opera,r=/Trident\//.test(t),i=/WebKit\//.test(t);return{isOpera:n,isIE8:e.ie===8,isIE:r,isGecko:/Gecko\//.test(t),isWebKit:i,isIOS:/iP(?:ad|hone|od)/.test(t),useTextFixer:r||n,cantFocusEmptyTextNodes:r||i,losesSelectionOnBlur:r}}(window),DOMTreeWalker=function(){"use strict";var e={1:1,2:2,3:4,8:128,9:256,11:1024},t=1,n=function(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n};return n.prototype.nextNode=function(){var n=this.currentNode,r=this.root,i=this.nodeType,s=this.filter,o;for(;;){o=n.firstChild;while(!o&&n){if(n===r)break;o=n.nextSibling,o||(n=n.parentNode)}if(!o)return null;if(e[o.nodeType]&i&&s(o)===t)return this.currentNode=o,o;n=o}},n.prototype.previousNode=function(){var n=this.currentNode,r=this.root,i=this.nodeType,s=this.filter,o;for(;;){if(n===r)return null;o=n.previousSibling;if(o)while(n=o.lastChild)o=n;else o=n.parentNode;if(!o)return null;if(e[o.nodeType]&i&&s(o)===t)return this.currentNode=o,o;n=o}},n}();(function(e,t){"use strict";var n=function(e,t){var n=e.length,r,i;while(n--){r=e[n].prototype;for(i in t)r[i]=t[i]}},r=function(e,t){var n=e.length;while(n--)if(!t(e[n]))return!1;return!0},i=function(){return!1},s=function(){return!0},o=/^(?:A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:FN|EL)|EM|FONT|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TRONG|AMP)|U)$/,u={BR:1,IMG:1,INPUT:1},a=function(e,t){var n=t.parentNode;return n&&n.replaceChild(e,t),e},f=1,l=3,c=1,h=1,p=3,d=function(e){return e.isBlock()?h:p};n(window.Node?[Node]:[Text,Element,HTMLDocument],{isInline:i,isBlock:i,isContainer:i,getPath:function(){var e=this.parentNode;return e?e.getPath():""},detach:function(){var e=this.parentNode;return e&&e.removeChild(this),this},replaceWith:function(e){return a(e,this),this},replaces:function(e){return a(this,e),this},nearest:function(e,t){var n=this.parentNode;return n?n.nearest(e,t):null},getPreviousBlock:function(){var e=this.ownerDocument,n=new t(e.body,c,d,!1);return n.currentNode=this,n.previousNode()},getNextBlock:function(){var e=this.ownerDocument,n=new t(e.body,c,d,!1);return n.currentNode=this,n.nextNode()},split:function(e,t){return e},mergeContainers:function(){}}),n([Text],{isLeaf:i,isInline:s,getLength:function(){return this.length},isLike:function(e){return e.nodeType===l},split:function(e,t){var n=this;return n===t?e:n.parentNode.split(n.splitText(e),t)}}),n([Element],{isLeaf:function(){return!!u[this.nodeName]},isInline:function(){return o.test(this.nodeName)},isBlock:function(){return!this.isInline()&&r(this.childNodes,function(e){return e.isInline()})},isContainer:function(){return!this.isInline()&&!this.isBlock()},getLength:function(){return this.childNodes.length},getPath:function(){var e=this.nodeName;if(e==="BODY")return e;var t=this.parentNode.getPath(),n=this.id,r=this.className.trim();return t+=">"+e,n&&(t+="#"+n),r&&(r=r.split(/\s\s*/),r.sort(),t+=".",t+=r.join(".")),t},wraps:function(e){return a(this,e).appendChild(e),this},empty:function(){var e=this.ownerDocument.createDocumentFragment(),t=this.childNodes.length;while(t--)e.appendChild(this.firstChild);return e},is:function(e,t){if(this.nodeName!==e)return!1;var n;for(n in t)if(this.getAttribute(n)!==t[n])return!1;return!0},nearest:function(e,t){var n=this;do if(n.is(e,t))return n;while((n=n.parentNode)&&n.nodeType===f);return null},isLike:function(e){return e.nodeType===f&&e.nodeName===this.nodeName&&e.className===this.className&&e.style.cssText===this.style.cssText},mergeInlines:function(e){var t=this.childNodes,n=t.length,r=[],i,s,o;while(n--){i=t[n],s=n&&t[n-1];if(n&&i.isInline()&&i.isLike(s)&&!u[i.nodeName])e.startContainer===i&&(e.startContainer=s,e.startOffset+=s.getLength()),e.endContainer===i&&(e.endContainer=s,e.endOffset+=s.getLength()),e.startContainer===this&&(e.startOffset>n?e.startOffset-=1:e.startOffset===n&&(e.startContainer=s,e.startOffset=s.getLength())),e.endContainer===this&&(e.endOffset>n?e.endOffset-=1:e.endOffset===n&&(e.endContainer=s,e.endOffset=s.getLength())),i.detach(),i.nodeType===l?s.appendData(i.data.replace(/\u200B/g,"")):r.push(i.empty());else if(i.nodeType===f){o=r.length;while(o--)i.appendChild(r.pop());i.mergeInlines(e)}}},mergeWithBlock:function(e,t){var n=this,r=e,i,s,o;while(r.parentNode.childNodes.length===1)r=r.parentNode;r.detach(),s=n.childNodes.length,i=n.lastChild,i&&i.nodeName==="BR"&&(n.removeChild(i),s-=1),o={startContainer:n,startOffset:s,endContainer:n,endOffset:s},n.appendChild(e.empty()),n.mergeInlines(o),t.setStart(o.startContainer,o.startOffset),t.collapse(!0),window.opera&&(i=n.lastChild)&&i.nodeName==="BR"&&n.removeChild(i)},mergeContainers:function(){var e=this.previousSibling,t=this.firstChild;e&&e.isLike(this)&&e.isContainer()&&(e.appendChild(this.detach().empty()),t&&t.mergeContainers())},split:function(e,t){var n=this;typeof e=="number"&&(e=e-1,s=n.compareBoundaryPoints(u,r)<1;return!i&&!s}var l=n.compareBoundaryPoints(o,r)<1,c=n.compareBoundaryPoints(a,r)>-1;return l&&c},moveBoundariesDownTree:function(){var e=this.startContainer,t=this.startOffset,n=this.endContainer,i=this.endOffset,s;while(e.nodeType!==r){s=e.childNodes[t];if(!s||s.isLeaf())break;e=s,t=0}if(i)while(n.nodeType!==r){s=n.childNodes[i-1];if(!s||s.isLeaf())break;n=s,i=n.getLength()}else while(n.nodeType!==r){s=n.firstChild;if(!s||s.isLeaf())break;n=s}return this.collapsed?(this.setStart(n,i),this.setEnd(e,t)):(this.setStart(e,t),this.setEnd(n,i)),this},moveBoundariesUpTree:function(e){var n=this.startContainer,r=this.startOffset,i=this.endContainer,s=this.endOffset,o;e||(e=this.commonAncestorContainer);while(n!==e&&!r)o=n.parentNode,r=t.call(o.childNodes,n),n=o;while(i!==e&&s===i.getLength())o=i.parentNode,s=t.call(o.childNodes,i)+1,i=o;return this.setStart(n,r),this.setEnd(i,s),this},getStartBlock:function(){var e=this.startContainer,t;return e.isInline()?t=e.getPreviousBlock():e.isBlock()?t=e:(t=l(e,this.startOffset),t=t.getNextBlock()),t&&this.containsNode(t,!0)?t:null},getEndBlock:function(){var e=this.endContainer,t,n;if(e.isInline())t=e.getPreviousBlock();else if(e.isBlock())t=e;else{t=c(e,this.endOffset);if(!t){t=e.ownerDocument.body;while(n=t.lastChild)t=n}t=t.getPreviousBlock()}return t&&this.containsNode(t,!0)?t:null},startsAtBlockBoundary:function(){var e=this.startContainer,n=this.startOffset,r,i;while(e.isInline()){if(n)return!1;r=e.parentNode,n=t.call(r.childNodes,e),e=r}while(n&&(i=e.childNodes[n-1])&&(i.data===""||i.nodeName==="BR"))n-=1;return!n},endsAtBlockBoundary:function(){var e=this.endContainer,n=this.endOffset,r=e.getLength(),i,s;while(e.isInline()){if(n!==r)return!1;i=e.parentNode,n=t.call(i.childNodes,e)+1,e=i,r=e.childNodes.length}while(n-1)e.deleteData(t,1);!e.data&&!e.nextSibling&&!e.previousSibling&&e.parentNode.isInline()&&e.parentNode.detach()}},j,F,I="",q=function(e,t){M&&!t&&B(e);var n=e.startContainer,r=e.endContainer,i;if(t||n!==j||r!==F)j=n,F=r,i=n&&r?n===r?r.getPath():"(selection)":"",I!==i&&(I=i,S("pathChange",{path:i}));n!==r&&S("select")},R=function(){q(O())};T("keyup",R),T("mouseup",R);var U=function(){h&&l.focus(),f.focus()},z=function(){h&&l.blur(),top.focus()};f.addEventListener("focus",x,!1),f.addEventListener("blur",x,!1);var W=function(){return l.innerHTML},X=function(e){var t=l;t.innerHTML=e;do t.fixCursor();while(t=t.getNextBlock())},V=function(e,t){t||(t=O()),t.collapse(!0),t._insertNode(e),t.setStartAfter(e),A(t),q(t)},$=Array.prototype.indexOf,J="ss-"+Date.now()+"-"+Math.random(),K="es-"+Date.now()+"-"+Math.random(),Q=function(e){var t=b("INPUT",{id:J,type:"hidden"}),n=b("INPUT",{id:K,type:"hidden"}),i;e._insertNode(t),e.collapse(!1),e._insertNode(n),t.compareDocumentPosition(n)&r&&(t.id=K,n.id=J,i=t,t=n,n=i),e.setStartAfter(t),e.setEndBefore(n)},G=function(t){var n=e.getElementById(J),r=e.getElementById(K);if(n&&r){var i=n.parentNode,s=r.parentNode,o,u={startContainer:i,endContainer:s,startOffset:$.call(i.childNodes,n),endOffset:$.call(s.childNodes,r)};i===s&&(u.endOffset-=1),n.detach(),r.detach(),i.mergeInlines(u),i!==s&&s.mergeInlines(u),t||(t=e.createRange()),t.setStart(u.startContainer,u.startOffset),t.setEnd(u.endContainer,u.endOffset),o=t.collapsed,t.moveBoundariesDownTree(),o&&t.collapse(!0)}return t},Y,Z,et,tt,nt=function(){tt&&(tt=!1,S("undoStateChange",{canUndo:!0,canRedo:!1})),S("input")};T("keyup",function(e){var t=e.keyCode;!e.ctrlKey&&!e.metaKey&&!e.altKey&&(t<16||t>20)&&(t<33||t>45)&&nt()});var rt=function(e){tt||(Y+=1,Yr.endOffset?d.splitText(r.endOffset):p=r.endOffset),d===r.startContainer&&(v&&r.startOffset?d=d.splitText(r.startOffset):h=r.startOffset),v&&(b(e,t).wraps(d),p=d.length),c=d,l||(l=c);while(d=f.nextNode());r=C(l,h,c,p)}return r},at=function(t,n,r,i){Q(r);var o;r.collapsed&&(m?(o=e.createTextNode("​"),H(o)):o=e.createTextNode(""),r._insertNode(o));var u=r.commonAncestorContainer;while(u.isInline())u=u.parentNode;var a=r.startContainer,f=r.startOffset,l=r.endContainer,c=r.endOffset,h=[],p=function(e,t){if(r.containsNode(e,!1))return;var n=e.nodeType===s,i,o;if(!r.containsNode(e,!0)){e.nodeName!=="INPUT"&&(!n||e.data)&&h.push([t,e]);return}if(n)e===l&&c!==e.length&&h.push([t,e.splitText(c)]),e===a&&f&&(e.splitText(f),h.push([t,e]));else for(i=e.firstChild;i;i=o)o=i.nextSibling,p(i,t)},d=Array.prototype.filter.call(u.getElementsByTagName(t),function(e){return r.containsNode(e,!0)&&e.is(t,n)});i||d.forEach(function(e){p(e,e)}),h.forEach(function(e){e[0].cloneNode(!1).wraps(e[1])}),d.forEach(function(e){e.replaceWith(e.empty())}),G(r),o&&r.collapse(!1);var v={startContainer:r.startContainer,startOffset:r.startOffset,endContainer:r.endContainer,endOffset:r.endOffset};return u.mergeInlines(v),r.setStart(v.startContainer,v.startOffset),r.setEnd(v.endContainer,v.endOffset),r},ft=function(e,t,n,r){if(!n&&!(n=O()))return;rt(n),G(n),t&&(n=at(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=ut(e.tag.toUpperCase(),e.attributes||{},n)),A(n),q(n,!0),nt()},lt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},ct=function(e,t,n){var r=lt[e.nodeName],i=t.split(n,e.parentNode);return i.nodeName!==r&&(e=b(r),e.className=i.dir==="rtl"?"dir-rtl":"",e.dir=i.dir,e.replaces(i).appendChild(i.empty()),i=e),i},ht=function(e,t,n){if(!n&&!(n=O()))return;t&&(rt(n),G(n));var r=n.getStartBlock(),i=n.getEndBlock();if(r&&i)do if(e(r)||r===i)break;while(r=r.getNextBlock());t&&(A(n),q(n,!0),nt())},pt=function(e,t){if(!t&&!(t=O()))return;c||l.setAttribute("contenteditable","false"),tt?Q(t):rt(t),t.expandToBlockBoundaries(),t.moveBoundariesUpTree(l);var n=t._extractContents(l);t._insertNode(e(n)),t.endOffset]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:[\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,4}))/i,St=function(e){var t=e.ownerDocument,r=new n(e,o,function(e){return e.nearest("A")?a:u},!1),i,s,f,l,c,h,p;while(i=r.nextNode()){s=i.data.split(Et),l=s.length;if(l>1){h=i.parentNode,p=i.nextSibling;for(f=0;f(e.documentElement.scrollTop||l.scrollTop)+l.offsetHeight&&a.scrollIntoView(!1),nt()},backspace:function(e){var t=O();if(!t.collapsed)e.preventDefault(),t._deleteContents(),A(t),q(t,!0);else if(t.startsAtBlockBoundary()){e.preventDefault();var n=t.getStartBlock(),r=n.getPreviousBlock();if(r){if(!r.isContentEditable){r.detach();return}r.mergeWithBlock(n,t),n=r.parentNode;while(n&&!n.nextSibling)n=n.parentNode;n&&(n=n.nextSibling)&&n.mergeContainers(),A(t)}else{if(n.nearest("UL")||n.nearest("OL"))return pt(wt,t);if(n.nearest("BLOCKQUOTE"))return pt(vt,t);A(t),q(t,!0)}}else setTimeout(Pt,0)},"delete":function(e){var t=O();if(!t.collapsed)e.preventDefault(),t._deleteContents(),A(t),q(t,!0);else if(t.endsAtBlockBoundary()){e.preventDefault();var n=t.getStartBlock(),r=n.getNextBlock();if(r){if(!r.isContentEditable){r.detach();return}n.mergeWithBlock(r,t),r=n.parentNode;while(r&&!r.nextSibling)r=r.parentNode;r&&(r=r.nextSibling)&&r.mergeContainers(),A(t),q(t,!0)}}else setTimeout(Pt,0)},space:function(){var e=O();rt(e),G(e),A(e)},"ctrl-b":Dt("B"),"ctrl-i":Dt("I"),"ctrl-u":Dt("U"),"ctrl-y":_t(st),"ctrl-z":_t(it),"ctrl-shift-z":_t(st)};T(c?"keypress":"keydown",function(e){var t=e.keyCode,n=Mt[t]||String.fromCharCode(t).toLowerCase(),r="";c&&e.which===46&&(n="."),111n?e.startOffset-=1:e.startOffset===n&&(e.startContainer=s,e.startOffset=s.getLength())),e.endContainer===this&&(e.endOffset>n?e.endOffset-=1:e.endOffset===n&&(e.endContainer=s,e.endOffset=s.getLength())),i.detach(),i.nodeType===l?s.appendData(i.data.replace(/\u200B/g,"")):r.push(i.empty());else if(i.nodeType===f){o=r.length;while(o--)i.appendChild(r.pop());i.mergeInlines(e)}}},mergeWithBlock:function(e,t){var n=this,r=e,i,s,o;while(r.parentNode.childNodes.length===1)r=r.parentNode;r.detach(),s=n.childNodes.length,i=n.lastChild,i&&i.nodeName==="BR"&&(n.removeChild(i),s-=1),o={startContainer:n,startOffset:s,endContainer:n,endOffset:s},n.appendChild(e.empty()),n.mergeInlines(o),t.setStart(o.startContainer,o.startOffset),t.collapse(!0),window.opera&&(i=n.lastChild)&&i.nodeName==="BR"&&n.removeChild(i)},mergeContainers:function(){var e=this.previousSibling,t=this.firstChild;e&&e.isLike(this)&&e.isContainer()&&(e.appendChild(this.detach().empty()),t&&t.mergeContainers())},split:function(e,t){var n=this;typeof e=="number"&&(e=e-1,s=n.compareBoundaryPoints(u,r)<1;return!i&&!s}var l=n.compareBoundaryPoints(o,r)<1,c=n.compareBoundaryPoints(a,r)>-1;return l&&c},moveBoundariesDownTree:function(){var e=this.startContainer,t=this.startOffset,n=this.endContainer,i=this.endOffset,s;while(e.nodeType!==r){s=e.childNodes[t];if(!s||s.isLeaf())break;e=s,t=0}if(i)while(n.nodeType!==r){s=n.childNodes[i-1];if(!s||s.isLeaf())break;n=s,i=n.getLength()}else while(n.nodeType!==r){s=n.firstChild;if(!s||s.isLeaf())break;n=s}return this.collapsed?(this.setStart(n,i),this.setEnd(e,t)):(this.setStart(e,t),this.setEnd(n,i)),this},moveBoundariesUpTree:function(e){var n=this.startContainer,r=this.startOffset,i=this.endContainer,s=this.endOffset,o;e||(e=this.commonAncestorContainer);while(n!==e&&!r)o=n.parentNode,r=t.call(o.childNodes,n),n=o;while(i!==e&&s===i.getLength())o=i.parentNode,s=t.call(o.childNodes,i)+1,i=o;return this.setStart(n,r),this.setEnd(i,s),this},getStartBlock:function(){var e=this.startContainer,t;return e.isInline()?t=e.getPreviousBlock():e.isBlock()?t=e:(t=l(e,this.startOffset),t=t.getNextBlock()),t&&this.containsNode(t,!0)?t:null},getEndBlock:function(){var e=this.endContainer,t,n;if(e.isInline())t=e.getPreviousBlock();else if(e.isBlock())t=e;else{t=c(e,this.endOffset);if(!t){t=e.ownerDocument.body;while(n=t.lastChild)t=n}t=t.getPreviousBlock()}return t&&this.containsNode(t,!0)?t:null},startsAtBlockBoundary:function(){var e=this.startContainer,n=this.startOffset,r,i;while(e.isInline()){if(n)return!1;r=e.parentNode,n=t.call(r.childNodes,e),e=r}while(n&&(i=e.childNodes[n-1])&&(i.data===""||i.nodeName==="BR"))n-=1;return!n},endsAtBlockBoundary:function(){var e=this.endContainer,n=this.endOffset,r=e.getLength(),i,s;while(e.isInline()){if(n!==r)return!1;i=e.parentNode,n=t.call(i.childNodes,e)+1,e=i,r=e.childNodes.length}while(n-1)e.deleteData(t,1);!e.data&&!e.nextSibling&&!e.previousSibling&&e.parentNode.isInline()&&e.parentNode.detach()}},j,F,I="",q=function(e,t){M&&!t&&B(e);var n=e.startContainer,r=e.endContainer,i;if(t||n!==j||r!==F)j=n,F=r,i=n&&r?n===r?r.getPath():"(selection)":"",I!==i&&(I=i,S("pathChange",{path:i}));n!==r&&S("select")},R=function(){q(O())};T("keyup",R),T("mouseup",R);var U=function(){h&&l.focus(),f.focus()},z=function(){h&&l.blur(),top.focus()};f.addEventListener("focus",x,!1),f.addEventListener("blur",x,!1);var W=function(){return l.innerHTML},X=function(e){var t=l;t.innerHTML=e;do t.fixCursor();while(t=t.getNextBlock())},V=function(e,t){t||(t=O()),t.collapse(!0),t._insertNode(e),t.setStartAfter(e),A(t),q(t)},$=Array.prototype.indexOf,J="squire-selection-start",K="squire-selection-end",Q=function(e){var t=b("INPUT",{id:J,type:"hidden"}),n=b("INPUT",{id:K,type:"hidden"}),i;e._insertNode(t),e.collapse(!1),e._insertNode(n),t.compareDocumentPosition(n)&r&&(t.id=K,n.id=J,i=t,t=n,n=i),e.setStartAfter(t),e.setEndBefore(n)},G=function(t){var n=e.getElementById(J),r=e.getElementById(K);if(n&&r){var i=n.parentNode,s=r.parentNode,o,u={startContainer:i,endContainer:s,startOffset:$.call(i.childNodes,n),endOffset:$.call(s.childNodes,r)};i===s&&(u.endOffset-=1),n.detach(),r.detach(),i.mergeInlines(u),i!==s&&s.mergeInlines(u),t||(t=e.createRange()),t.setStart(u.startContainer,u.startOffset),t.setEnd(u.endContainer,u.endOffset),o=t.collapsed,t.moveBoundariesDownTree(),o&&t.collapse(!0)}return t||null},Y,Z,et,tt,nt=function(){tt&&(tt=!1,S("undoStateChange",{canUndo:!0,canRedo:!1})),S("input")};T("keyup",function(e){var t=e.keyCode;!e.ctrlKey&&!e.metaKey&&!e.altKey&&(t<16||t>20)&&(t<33||t>45)&&nt()});var rt=function(e){tt||(Y+=1,Yr.endOffset?d.splitText(r.endOffset):p=r.endOffset),d===r.startContainer&&(v&&r.startOffset?d=d.splitText(r.startOffset):h=r.startOffset),v&&(b(e,t).wraps(d),p=d.length),c=d,l||(l=c);while(d=f.nextNode());r=C(l,h,c,p)}return r},at=function(t,n,r,i){Q(r);var o;r.collapsed&&(m?(o=e.createTextNode("​"),H(o)):o=e.createTextNode(""),r._insertNode(o));var u=r.commonAncestorContainer;while(u.isInline())u=u.parentNode;var a=r.startContainer,f=r.startOffset,l=r.endContainer,c=r.endOffset,h=[],p=function(e,t){if(r.containsNode(e,!1))return;var n=e.nodeType===s,i,o;if(!r.containsNode(e,!0)){e.nodeName!=="INPUT"&&(!n||e.data)&&h.push([t,e]);return}if(n)e===l&&c!==e.length&&h.push([t,e.splitText(c)]),e===a&&f&&(e.splitText(f),h.push([t,e]));else for(i=e.firstChild;i;i=o)o=i.nextSibling,p(i,t)},d=Array.prototype.filter.call(u.getElementsByTagName(t),function(e){return r.containsNode(e,!0)&&e.is(t,n)});i||d.forEach(function(e){p(e,e)}),h.forEach(function(e){e[0].cloneNode(!1).wraps(e[1])}),d.forEach(function(e){e.replaceWith(e.empty())}),G(r),o&&r.collapse(!1);var v={startContainer:r.startContainer,startOffset:r.startOffset,endContainer:r.endContainer,endOffset:r.endOffset};return u.mergeInlines(v),r.setStart(v.startContainer,v.startOffset),r.setEnd(v.endContainer,v.endOffset),r},ft=function(e,t,n,r){if(!n&&!(n=O()))return;rt(n),G(n),t&&(n=at(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=ut(e.tag.toUpperCase(),e.attributes||{},n)),A(n),q(n,!0),nt()},lt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},ct=function(e,t,n){var r=lt[e.nodeName],i=t.split(n,e.parentNode);return i.nodeName!==r&&(e=b(r),e.className=i.dir==="rtl"?"dir-rtl":"",e.dir=i.dir,e.replaces(i).appendChild(i.empty()),i=e),i},ht=function(e,t,n){if(!n&&!(n=O()))return;t&&(rt(n),G(n));var r=n.getStartBlock(),i=n.getEndBlock();if(r&&i)do if(e(r)||r===i)break;while(r=r.getNextBlock());t&&(A(n),q(n,!0),nt())},pt=function(e,t){if(!t&&!(t=O()))return;c||l.setAttribute("contenteditable","false"),tt?Q(t):rt(t),t.expandToBlockBoundaries(),t.moveBoundariesUpTree(l);var n=t._extractContents(l);t._insertNode(e(n)),t.endOffset]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:[\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,4}))/i,St=function(e){var t=e.ownerDocument,r=new n(e,o,function(e){return e.nearest("A")?a:u},!1),i,s,f,l,c,h,p;while(i=r.nextNode()){s=i.data.split(Et),l=s.length;if(l>1){h=i.parentNode,p=i.nextSibling;for(f=0;f(e.documentElement.scrollTop||l.scrollTop)+l.offsetHeight&&a.scrollIntoView(!1),nt()},backspace:function(e){var t=O();if(!t.collapsed)e.preventDefault(),t._deleteContents(),A(t),q(t,!0);else if(t.startsAtBlockBoundary()){e.preventDefault();var n=t.getStartBlock(),r=n.getPreviousBlock();if(r){if(!r.isContentEditable){r.detach();return}r.mergeWithBlock(n,t),n=r.parentNode;while(n&&!n.nextSibling)n=n.parentNode;n&&(n=n.nextSibling)&&n.mergeContainers(),A(t)}else{if(n.nearest("UL")||n.nearest("OL"))return pt(wt,t);if(n.nearest("BLOCKQUOTE"))return pt(vt,t);A(t),q(t,!0)}}else setTimeout(Pt,0)},"delete":function(e){var t=O();if(!t.collapsed)e.preventDefault(),t._deleteContents(),A(t),q(t,!0);else if(t.endsAtBlockBoundary()){e.preventDefault();var n=t.getStartBlock(),r=n.getNextBlock();if(r){if(!r.isContentEditable){r.detach();return}n.mergeWithBlock(r,t),r=n.parentNode;while(r&&!r.nextSibling)r=r.parentNode;r&&(r=r.nextSibling)&&r.mergeContainers(),A(t),q(t,!0)}}else setTimeout(Pt,0)},space:function(){var e=O();rt(e),G(e),A(e)},"ctrl-b":Dt("B"),"ctrl-i":Dt("I"),"ctrl-u":Dt("U"),"ctrl-y":_t(st),"ctrl-z":_t(it),"ctrl-shift-z":_t(st)};T(c?"keypress":"keydown",function(e){var t=e.keyCode,n=Mt[t]||String.fromCharCode(t).toLowerCase(),r="";c&&e.which===46&&(n="."),111