From 8684c2315bd9f8e0d2ed45228c8fb3de5e6efd3a Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 26 May 2016 11:40:42 +1000 Subject: [PATCH] Update to latest Squire build --- build/squire-raw.js | 24 ++++++++++++++++-------- build/squire.js | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 62dbbd8..d42094a 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -1098,7 +1098,7 @@ var getEndBlockOfRange = function ( range, root ) { block = container; } else { block = getNodeAfter( container, range.endOffset ); - if ( !block ) { + if ( !block || !isOrContains( root, block ) ) { block = root; while ( child = block.lastChild ) { block = child; @@ -1120,8 +1120,9 @@ var contentWalker = new TreeWalker( null, ); var rangeDoesStartAtBlockBoundary = function ( range, root ) { - var startContainer = range.startContainer, - startOffset = range.startOffset; + var startContainer = range.startContainer; + var startOffset = range.startOffset; + var nodeAfterCursor; // If in the middle or end of a text node, we're not at the boundary. contentWalker.root = null; @@ -1129,16 +1130,23 @@ var rangeDoesStartAtBlockBoundary = function ( range, root ) { if ( startOffset ) { return false; } - contentWalker.currentNode = startContainer; + nodeAfterCursor = startContainer; } else { - contentWalker.currentNode = getNodeAfter( startContainer, startOffset ); - - if ( !contentWalker.currentNode ) { - contentWalker.currentNode = startContainer; + nodeAfterCursor = getNodeAfter( startContainer, startOffset ); + if ( nodeAfterCursor && !isOrContains( root, nodeAfterCursor ) ) { + nodeAfterCursor = null; + } + // The cursor was right at the end of the document + if ( !nodeAfterCursor ) { + nodeAfterCursor = getNodeBefore( startContainer, startOffset ); + if ( node.nodeType === TEXT_NODE && node.length ) { + return false; + } } } // Otherwise, look for any previous content in the same block. + contentWalker.currentNode = nodeAfterCursor; contentWalker.root = getStartBlockOfRange( range, root ); return !contentWalker.previousNode(); diff --git a/build/squire.js b/build/squire.js index 295bd6b..f78c706 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1,2 +1,2 @@ -!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(e){return e.nodeType===P&&!!ct[e.nodeName]}function i(e){return lt.test(e.nodeName)}function a(e){var t=e.nodeType;return(t===P||t===F)&&!i(e)&&r(e.childNodes,i)}function s(e){var t=e.nodeType;return!(t!==P&&t!==F||i(e)||a(e))}function d(e,t){var r=new n(t,M,a);return r.currentNode=e,r}function l(e,t){return e=d(e,t).previousNode(),e!==t?e:null}function c(e,t){return e=d(e,t).nextNode(),e!==t?e:null}function h(e,t){return!o(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&"A"!==e.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function f(e,t,n){if(e.nodeName!==t)return!1;for(var r in n)if(e.getAttribute(r)!==n[r])return!1;return!0}function u(e,t,n,r){for(;e&&e!==t;){if(f(e,n,r))return e;e=e.parentNode}return null}function p(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function g(e,t){var n,r,o,i,a="";return e&&e!==t&&(a=g(e.parentNode,t),e.nodeType===P&&(a+=(a?">":"")+e.nodeName,(n=e.id)&&(a+="#"+n),(r=e.className.trim())&&(o=r.split(/\s\s*/),o.sort(),a+=".",a+=o.join(".")),(i=e.dir)&&(a+="[dir="+i+"]"))),a}function m(e){var t=e.nodeType;return t===P?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function _(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=k(a).createDefaultBlock(),r?e.replaceChild(n,r):e.appendChild(n),e=n,n=null)),e.nodeType===I)return s;if(i(e)){for(r=e.firstChild;rt&&r&&r.nodeType===I&&!r.data;)e.removeChild(r),r=e.firstChild;r||(rt?(n=a.createTextNode(Z),k(a)._didAddZWS()):n=a.createTextNode(""))}else if(nt){for(;e.nodeType!==I&&!o(e);){if(r=e.firstChild,!r){n=a.createTextNode("");break}e=r}e.nodeType===I?/^ +$/.test(e.data)&&(e.data=""):o(e)&&e.parentNode.insertBefore(a.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=S(a,"BR");(r=e.lastElementChild)&&!i(r);)e=r;if(n)try{e.appendChild(n)}catch(d){k(a).didError({name:"Squire: fixCursor – "+d,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return s}function y(e,t){var n,r,o,a,d=e.childNodes,l=e.ownerDocument,c=null,h=k(l)._config;for(n=0,r=d.length;r>n;n+=1)o=d[n],a="BR"===o.nodeName,!a&&i(o)?(c||(c=S(l,h.blockTag,h.blockAttributes)),c.appendChild(o),n-=1,r-=1):(a||c)&&(c||(c=S(l,h.blockTag,h.blockAttributes)),_(c,t),a?e.replaceChild(c,o):(e.insertBefore(c,o),n+=1,r+=1),c=null),s(o)&&y(o,t);return c&&e.appendChild(_(c,t)),e}function T(e,t,n,r){var o,i,a,s=e.nodeType;if(s===I&&e!==n)return T(e.parentNode,e.splitText(t),n,r);if(s===P){if("number"==typeof t&&(t=ts?t.startOffset-=1:t.startOffset===s&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=r,t.endOffset=m(r))),v(n),n.nodeType===I?r.appendData(n.data):d.push(N(n));else if(n.nodeType===P){for(o=d.length;o--;)n.appendChild(d.pop());b(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(a),o=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),o-=1),i={startContainer:e,startOffset:o,endContainer:e,endOffset:o},e.appendChild(N(t)),b(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),X&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function x(e,t){var n,r,o=e.previousSibling,i=e.firstChild,a=e.ownerDocument,d="LI"===e.nodeName;if(!d||i&&/^[OU]L$/.test(i.nodeName))if(o&&h(o,e)){if(!s(o)){if(!d)return;r=S(a,"DIV"),r.appendChild(N(o)),o.appendChild(r)}v(e),n=!s(e),o.appendChild(N(e)),n&&y(o,t),i&&x(i,t)}else d&&(o=S(a,"DIV"),e.insertBefore(o,i),_(o,t))}function k(e){for(var t,n=jt.length;n--;)if(t=jt[n],t._doc===e)return t;return null}function O(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?O(e[n],r):r;return e}function B(e,t){e.nodeType===w&&(e=e.body);var n,r=e.ownerDocument,o=r.defaultView;this._win=o,this._doc=r,this._root=e,this._events={},this._lastSelection=null,ot&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="","onselectionchange"in r?this.addEventListener("selectionchange",this._updatePathOnEvent):(this.addEventListener("keyup",this._updatePathOnEvent),this.addEventListener("mouseup",this._updatePathOnEvent)),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,this._ignoreAllChanges=!1,it?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._restoreSelection=!1,this.addEventListener("blur",L),this.addEventListener("input",A),this.addEventListener("mousedown",A),this.addEventListener("touchstart",A),this.addEventListener("focus",D),this._awaitingPaste=!1,this.addEventListener(Y?"beforecut":"cut",Kt),this.addEventListener("copy",Zt),this.addEventListener(Y?"beforepaste":"paste",Gt),this.addEventListener(X?"keypress":"keydown",kt),this._keyHandlers=Object.create(At),this.setConfig(t),Y&&(o.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,r=this.parentNode,o=this.length-e;return n?r.insertBefore(t,n):r.appendChild(t),o&&this.deleteData(e,o),t}),e.setAttribute("contenteditable","true");try{r.execCommand("enableObjectResizing",!1,"false"),r.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}jt.push(this),this.setHTML("")}function L(){this._restoreSelection=!0}function A(){this._restoreSelection=!1}function D(){this._restoreSelection&&this.setSelection(this._lastSelection)}function R(e,t,n){var r,o;for(r=t.firstChild;r;r=o){if(o=r.nextSibling,i(r)){if(r.nodeType===I||"BR"===r.nodeName||"IMG"===r.nodeName){n.appendChild(r);continue}}else if(a(r)){n.appendChild(e.createDefaultBlock([R(e,r,e._doc.createDocumentFragment())]));continue}R(e,r,n)}return n}var U=2,P=1,I=3,w=9,F=11,M=1,H=4,W=0,z=1,q=2,K=3,Z="​",G=e.defaultView,j=navigator.userAgent,Q=/iP(?:ad|hone|od)/.test(j),V=/Mac OS X/.test(j),$=/Gecko\//.test(j),Y=/Trident\/[456]\./.test(j),X=!!G.opera,J=/Edge\//.test(j),et=!J&&/WebKit\//.test(j),tt=V?"meta-":"ctrl-",nt=Y||X,rt=Y||et,ot=Y,it="undefined"!=typeof MutationObserver,at=/[^ \t\r\n]/,st=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var dt={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)e=t.previousSibling,e||(t=t.parentNode);if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var lt=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|U|VAR|WBR)$/,ct={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},ht=function(e,t){for(var n=e.childNodes;t&&e.nodeType===P;)e=n[t-1],n=e.childNodes,t=n.length;return e},ft=function(e,t){if(e.nodeType===P){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(z,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(W,r)<1,s=e.compareBoundaryPoints(q,r)>-1;return a&&s},Ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,i=e.endContainer,a=e.endOffset;n.nodeType!==I&&(t=n.childNodes[r],t&&!o(t));)n=t,r=0;if(a)for(;i.nodeType!==I&&(t=i.childNodes[a-1],t&&!o(t));)i=t,a=m(i);else for(;i.nodeType!==I&&(t=i.firstChild,t&&!o(t));)i=t;e.collapsed?(e.setStart(i,a),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(i,a))},Nt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=st.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=st.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},St=function(e,t){var n,r=e.startContainer;return i(r)?n=l(r,t):a(r)?n=r:(n=ht(r,e.startOffset),n=c(n,t)),n&&vt(e,n,!0)?n:null},_t=function(e,t){var n,r,o=e.endContainer;if(i(o))n=l(o,t);else if(a(o))n=o;else{if(n=ft(o,e.endOffset),!n)for(n=t;r=n.lastChild;)n=r;n=l(n,t)}return n&&vt(e,n,!0)?n:null},yt=new n(null,H|M,function(e){return e.nodeType===I?at.test(e.data):"IMG"===e.nodeName}),Tt=function(e,t){var n=e.startContainer,r=e.startOffset;if(yt.root=null,n.nodeType===I){if(r)return!1;yt.currentNode=n}else yt.currentNode=ft(n,r),yt.currentNode||(yt.currentNode=n);return yt.root=St(e,t),!yt.previousNode()},bt=function(e,t){var n,r=e.endContainer,o=e.endOffset;if(yt.root=null,r.nodeType===I){if(n=r.data.length,n&&n>o)return!1;yt.currentNode=r}else yt.currentNode=ht(r,o);return yt.root=_t(e,t),!yt.nextNode()},Et=function(e,t){var n,r=St(e,t),o=_t(e,t);r&&o&&(n=r.parentNode,e.setStart(n,st.call(n.childNodes,r)),n=o.parentNode,e.setEnd(n,st.call(n.childNodes,o)+1))},xt={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},kt=function(e){var t=e.keyCode,n=xt[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),X&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-")),e.shiftKey&&(r+="shift-"),n=r+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,o):1!==n.length||o.collapsed||(this.saveUndoState(o),gt(o,this._root),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},Ot=function(e){return function(t,n){n.preventDefault(),t[e]()}},Bt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Lt=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===I&&(r=r.parentNode),n=r;i(n)&&(!n.textContent||n.textContent===Z);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,st.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),a(n)||(n=l(n,e._root)),_(n,e._root),Ct(t)),r===e._root&&(r=r.firstChild)&&"BR"===r.nodeName&&v(r),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(o){e.didError(o)}},At={enter:function(e,t,n){var r,o,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),un(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||gt(n,a),r=St(n,a),!r||/^T[HD]$/.test(r.nodeName))return ut(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((o=u(r,a,"LI"))&&(r=o),!r.textContent){if(u(r,a,"UL")||u(r,a,"OL"))return e.modifyBlocks(hn,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(on,n)}for(i=tn(e,r,n.startContainer,n.startOffset),Yt(r),Ht(r),_(r,a);i.nodeType===P;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===Z)){d=e._doc.createTextNode(""),C(i,d),i=d;break}for(;d&&d.nodeType===I&&!d.data&&(s=d.nextSibling,s&&"BR"!==s.nodeName);)v(d),d=s;if(!d||"BR"===d.nodeName||d.nodeType===I&&!X)break;i=d}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){var r=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Tt(n,r)){t.preventDefault();var o,i=St(n,r);if(!i)return;if(y(i.parentNode,r),o=l(i,r)){if(!o.isContentEditable)return void v(o);for(E(o,i,n),i=o.parentNode;i!==r&&!i.nextSibling;)i=i.parentNode;i!==r&&(i=i.nextSibling)&&x(i,r),e.setSelection(n)}else if(i){if(u(i,r,"UL")||u(i,r,"OL"))return e.modifyBlocks(hn,n);if(u(i,r,"BLOCKQUOTE"))return e.modifyBlocks(rn,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Lt(e)},0);else t.preventDefault(),gt(n,r),Lt(e,n)},"delete":function(e,t,n){var r,o,i,a,s,d,l=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(bt(n,l)){if(t.preventDefault(),r=St(n,l),!r)return;if(y(r.parentNode,l),o=c(r,l)){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o!==l&&!o.nextSibling;)o=o.parentNode;o!==l&&(o=o.nextSibling)&&x(o,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(i=n.cloneRange(),Nt(n,e._root),a=n.endContainer,s=n.endOffset,a.nodeType===P&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),v(d),Ct(n),void Lt(e,n);e.setSelection(i),setTimeout(function(){Lt(e)},0)}else t.preventDefault(),gt(n,l),Lt(e,n)},tab:function(e,t,n){var r,o,i=e._root;if(e._removeZWS(),n.collapsed&&Tt(n,i))for(r=St(n,i);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(cn,n));break}r=o}},"shift-tab":function(e,t,n){var r,o=e._root;e._removeZWS(),n.collapsed&&Tt(n,o)&&(r=n.startContainer,(u(r,o,"UL")||u(r,o,"OL"))&&(t.preventDefault(),e.modifyBlocks(hn,n)))},space:function(e,t,n){var r,o;e._recordUndoState(n),un(n.startContainer,e._root,e),e._getRangeAndRemoveBookmark(n),r=n.endContainer,o=r.parentNode,n.collapsed&&"A"===o.nodeName&&!r.nextSibling&&n.endOffset===m(r)&&n.setStartAfter(o),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&$&&(At["meta-left"]=function(e,t){t.preventDefault();var n=$t(e);n&&n.modify&&n.modify("move","backward","lineboundary")},At["meta-right"]=function(e,t){t.preventDefault();var n=$t(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),V||(At.pageup=function(e){e.moveCursorToStart()},At.pagedown=function(e){e.moveCursorToEnd()}),At[tt+"b"]=Bt("B"),At[tt+"i"]=Bt("I"),At[tt+"u"]=Bt("U"),At[tt+"shift-7"]=Bt("S"),At[tt+"shift-5"]=Bt("SUB",{tag:"SUP"}),At[tt+"shift-6"]=Bt("SUP",{tag:"SUB"}),At[tt+"shift-8"]=Ot("makeUnorderedList"),At[tt+"shift-9"]=Ot("makeOrderedList"),At[tt+"["]=Ot("decreaseQuoteLevel"),At[tt+"]"]=Ot("increaseQuoteLevel"),At[tt+"y"]=Ot("redo"),At[tt+"z"]=Ot("undo"),At[tt+"shift-z"]=Ot("redo");var Dt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Rt={backgroundColor:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color:"+t})}},color:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ut=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Pt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Rt)r=Rt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ut("B"),EM:Ut("I"),STRIKE:Ut("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+Dt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},It=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/,wt=/^(?:HEAD|META|STYLE)/,Ft=new n(null,H|M,function(){return!0}),Mt=function mn(e,t){var n,r,o,a,s,d,l,c,h,f,u,p,g=e.childNodes;for(n=e;i(n);)n=n.parentNode;for(Ft.root=n,r=0,o=g.length;o>r;r+=1)if(a=g[r],s=a.nodeName,d=a.nodeType,l=Pt[s],d===P){if(c=a.childNodes.length,l)a=l(a,e);else{if(wt.test(s)){e.removeChild(a),r-=1,o-=1;continue}if(!It.test(s)&&!i(a)){r-=1,o+=c-1,e.replaceChild(N(a),a);continue}}c&&mn(a,t||"PRE"===s)}else{if(d===I){if(u=a.data,h=!at.test(u.charAt(0)),f=!at.test(u.charAt(u.length-1)),t||!h&&!f)continue;if(h){for(Ft.currentNode=a;(p=Ft.previousPONode())&&(s=p.nodeName,!("IMG"===s||"#text"===s&&/\S/.test(p.data)));)if(!i(p)){p=null;break}u=u.replace(/^\s+/g,p?" ":"")}if(f){for(Ft.currentNode=a;(p=Ft.nextNode())&&!("IMG"===s||"#text"===s&&/\S/.test(p.data));)if(!i(p)){p=null;break}u=u.replace(/\s+$/g,p?" ":"")}if(u){a.data=u;continue}}e.removeChild(a),r-=1,o-=1}return e},Ht=function vn(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==P||o(t)?t.nodeType!==I||t.data||e.removeChild(t):(vn(t),i(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e){return e.nodeType===P?"BR"===e.nodeName:at.test(e.data)},zt=function(e){for(var t,r=e.parentNode;i(r);)r=r.parentNode;return t=new n(r,M|H,Wt),t.currentNode=e,!!t.nextNode()},qt=function(e,t){var n,r,o,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=zt(a[n]);for(;d--;)r=a[d],o=r.parentNode,o&&(s[d]?i(o)||y(o,t):v(r))},Kt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._root,i=this;this.saveUndoState(n),J||Q||!t?setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0):(Nt(n,o),r.appendChild(gt(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},Zt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");J||Q||!t||(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},Gt=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,h=this;if(!J&&s){for(e.preventDefault(),t=s.length;t--;){if(n=s[t],r=n.type,"text/html"===r)return void n.getAsString(function(e){h.insertHTML(e,!0)});"text/plain"===r&&(c=n),/^image\/.*/.test(r)&&(l=!0)}return void(l?(this.fireEvent("dragover",{dataTransfer:a,preventDefault:function(){d=!0}}),d&&this.fireEvent("drop",{dataTransfer:a})):c&&n.getAsString(function(e){h.insertPlainText(e,!0)}))}if(o=a&&a.types,!J&&o&&(st.call(o,"text/html")>-1||!$&&st.call(o,"text/plain")>-1&&st.call(o,"text/rtf")<0))return e.preventDefault(),void((i=a.getData("text/html"))?this.insertHTML(i,!0):((i=a.getData("text/plain"))||(i=a.getData("text/uri-list")))&&this.insertPlainText(i,!0));this._awaitingPaste=!0;var f=this._doc.body,u=this.getSelection(),p=u.startContainer,g=u.startOffset,m=u.endContainer,C=u.endOffset,N=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(N),u.selectNodeContents(N),this.setSelection(u),setTimeout(function(){try{h._awaitingPaste=!1;for(var e,t,n="",r=N;N=r;)r=N.nextSibling,v(N),e=N.firstChild,e&&e===N.lastChild&&"DIV"===e.nodeName&&(N=e),n+=N.innerHTML;t=h._createRange(p,g,m,C),h.setSelection(t),n&&h.insertHTML(n,!0)}catch(o){h.didError(o)}},0)},jt=[],Qt=B.prototype;Qt.setConfig=function(e){return e=O({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},Qt.createElement=function(e,t,n){return S(this._doc,e,t,n)},Qt.createDefaultBlock=function(e){var t=this._config;return _(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},Qt.didError=function(e){console.log(e)},Qt.getDocument=function(){return this._doc},Qt.getRoot=function(){return this._root},Qt.modifyDocument=function(e){this._ignoreAllChanges=!0,this._mutation&&this._mutation.disconnect(),e(),this._ignoreAllChanges=!1,this._mutation&&this._mutation.observe(this._root,{childList:!0,attributes:!0,characterData:!0,subtree:!0})};var Vt={pathChange:1,select:1,input:1,undoStateChange:1};Qt.fireEvent=function(e,t){var n,r,o=this._events[e];if(o)for(t||(t={}),t.type!==e&&(t.type=e),o=o.slice(),n=o.length;n--;){r=o[n];try{r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(i){i.details="Squire: fireEvent error. Event type: "+e,this.didError(i)}}return this},Qt.destroy=function(){var e,t=jt.length,n=this._events;for(e in n)this.removeEventListener(e);for(this._mutation&&this._mutation.disconnect();t--;)jt[t]===this&&jt.splice(t,1)},Qt.handleEvent=function(e){this.fireEvent(e.type,e)},Qt.addEventListener=function(e,t){var n=this._events[e],r=this._root;return t?(n||(n=this._events[e]=[],Vt[e]||("selectionchange"===e&&(r=this._doc),r.addEventListener(e,this,!0))),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Qt.removeEventListener=function(e,t){var n,r=this._events[e],o=this._root;if(r){if(t)for(n=r.length;n--;)r[n]===t&&r.splice(n,1);else r.length=0;r.length||(delete this._events[e],Vt[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},Qt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Qt.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,r=e.getBoundingClientRect();return r&&!r.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=Z,ut(e,t),r=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),b(n,{startContainer:e.startContainer,endContainer:e.endContainer,startOffset:e.startOffset,endOffset:e.endOffset})),r},Qt._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return Ct(n),this.setSelection(n),this},Qt.moveCursorToStart=function(){return this._moveCursorTo(!0)},Qt.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var $t=function(e){return e._win.getSelection()||null};Qt.setSelection=function(e){if(e){this._restoreSelection=!1,this._lastSelection=e,Q&&this._win.focus();var t=$t(this);t&&(t.removeAllRanges(),t.addRange(e))}return this},Qt.getSelection=function(){var e,t,n,r=$t(this),i=this._root;return r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&o(t)&&e.setStartBefore(t),n&&o(n)&&e.setEndBefore(n)),e&&p(i,e.commonAncestorContainer)?this._lastSelection=e:e=this._lastSelection,e||(e=this._createRange(i.firstChild,0)),e},Qt.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,H|M,function(e){return vt(t,e,!0)}),o=t.startContainer,a=t.endContainer,s=r.currentNode=o,d="",l=!1;for(r.filter(s)||(s=r.nextNode());s;)s.nodeType===I?(e=s.data,e&&/\S/.test(e)&&(s===a&&(e=e.slice(0,t.endOffset)),s===o&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===s.nodeName||l&&!i(s))&&(d+="\n",l=!1),s=r.nextNode();return d},Qt.getPath=function(){return this._path};var Yt=function(e){for(var t,r,o,a=new n(e,H,function(){return!0},!1);r=a.nextNode();)for(;(o=r.data.indexOf(Z))>-1;){if(1===r.length){do t=r.parentNode,t.removeChild(r),r=t,a.currentNode=t;while(i(r)&&!m(r));break}r.deleteData(o,1)}};Qt._didAddZWS=function(){this._hasZWS=!0},Qt._removeZWS=function(){this._hasZWS&&(Yt(this._root),this._hasZWS=!1)},Qt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?g(o,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},Qt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Qt.focus=function(){return this._root.focus(),this},Qt.blur=function(){return this._root.blur(),this};var Xt="squire-selection-start",Jt="squire-selection-end";Qt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Xt,type:"hidden"}),r=this.createElement("INPUT",{id:Jt,type:"hidden"});ut(e,n),e.collapse(!1),ut(e,r),n.compareDocumentPosition(r)&U&&(n.id=Jt,r.id=Xt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Qt._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+Xt),r=t.querySelector("#"+Jt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:st.call(i.childNodes,n),endOffset:st.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),b(i,s),i!==a&&b(a,s),e||(e=this._doc.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,o&&(i=e.startContainer,i.nodeType===I&&(a=i.childNodes[e.startOffset],a&&a.nodeType===I||(a=i.childNodes[e.startOffset-1]),a&&a.nodeType===I&&(e.setStart(a,0),e.collapse(!0))))}return e||null},Qt._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},Qt._docWasChanged=function(){if(!this._ignoreAllChanges){if(it&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},Qt._recordUndoState=function(e){if(!this._isInUndoState){var t=this._undoIndex+=1,n=this._undoStack;te+1&&this._isInUndoState){this._undoIndex+=1,this._setHTML(this._undoStack[this._undoIndex]);var n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:t>e+2}),this.fireEvent("input")}return this},Qt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;!r.collapsed&&r.startContainer.nodeType===I&&r.startOffset===r.startContainer.length&&r.startContainer.nextSibling&&r.setStartBefore(r.startContainer.nextSibling),!r.collapsed&&r.endContainer.nodeType===I&&0===r.endOffset&&r.endContainer.previousSibling&&r.setEndAfter(r.endContainer.previousSibling);var o,i,a=this._root,s=r.commonAncestorContainer;if(u(s,a,e,t))return!0;if(s.nodeType===I)return!1;o=new n(s,H,function(e){return vt(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},Qt.getFontInfo=function(e){var n,r,o,i={color:t,backgroundColor:t,family:t,size:t},a=0;if(!e&&!(e=this.getSelection()))return i;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===I)for(n.nodeType===I&&(n=n.parentNode);4>a&&n;)(r=n.style)&&(!i.color&&(o=r.color)&&(i.color=o,a+=1),!i.backgroundColor&&(o=r.backgroundColor)&&(i.backgroundColor=o,a+=1),!i.family&&(o=r.fontFamily)&&(i.family=o,a+=1),!i.size&&(o=r.fontSize)&&(i.size=o,a+=1)),n=n.parentNode;return i},Qt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,h,f=this._root;if(r.collapsed)o=_(this.createElement(e,t),f),ut(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{if(i=new n(r.commonAncestorContainer,H|M,function(e){return(e.nodeType===I||"BR"===e.nodeName||"IMG"===e.nodeName)&&vt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,i.filter(a)||(a=i.nextNode(),d=0),!a)return r;do c=i.currentNode,h=!u(c,f,e,t),h&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),s===a&&(s=c,l-=d),a=c,d=0),o=this.createElement(e,t),C(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==I&&(c.nodeType===I?(s=c,l=c.length):(s=c.parentNode,l=1)),r=this._createRange(a,d,s,l) +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(e){return e.nodeType===P&&!!ct[e.nodeName]}function i(e){return lt.test(e.nodeName)}function a(e){var t=e.nodeType;return(t===P||t===F)&&!i(e)&&r(e.childNodes,i)}function s(e){var t=e.nodeType;return!(t!==P&&t!==F||i(e)||a(e))}function d(e,t){var r=new n(t,M,a);return r.currentNode=e,r}function l(e,t){return e=d(e,t).previousNode(),e!==t?e:null}function c(e,t){return e=d(e,t).nextNode(),e!==t?e:null}function h(e,t){return!o(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&"A"!==e.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function f(e,t,n){if(e.nodeName!==t)return!1;for(var r in n)if(e.getAttribute(r)!==n[r])return!1;return!0}function u(e,t,n,r){for(;e&&e!==t;){if(f(e,n,r))return e;e=e.parentNode}return null}function p(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function g(e,t){var n,r,o,i,a="";return e&&e!==t&&(a=g(e.parentNode,t),e.nodeType===P&&(a+=(a?">":"")+e.nodeName,(n=e.id)&&(a+="#"+n),(r=e.className.trim())&&(o=r.split(/\s\s*/),o.sort(),a+=".",a+=o.join(".")),(i=e.dir)&&(a+="[dir="+i+"]"))),a}function m(e){var t=e.nodeType;return t===P?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function _(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=k(a).createDefaultBlock(),r?e.replaceChild(n,r):e.appendChild(n),e=n,n=null)),e.nodeType===I)return s;if(i(e)){for(r=e.firstChild;rt&&r&&r.nodeType===I&&!r.data;)e.removeChild(r),r=e.firstChild;r||(rt?(n=a.createTextNode(Z),k(a)._didAddZWS()):n=a.createTextNode(""))}else if(nt){for(;e.nodeType!==I&&!o(e);){if(r=e.firstChild,!r){n=a.createTextNode("");break}e=r}e.nodeType===I?/^ +$/.test(e.data)&&(e.data=""):o(e)&&e.parentNode.insertBefore(a.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=S(a,"BR");(r=e.lastElementChild)&&!i(r);)e=r;if(n)try{e.appendChild(n)}catch(d){k(a).didError({name:"Squire: fixCursor – "+d,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return s}function y(e,t){var n,r,o,a,d=e.childNodes,l=e.ownerDocument,c=null,h=k(l)._config;for(n=0,r=d.length;r>n;n+=1)o=d[n],a="BR"===o.nodeName,!a&&i(o)?(c||(c=S(l,h.blockTag,h.blockAttributes)),c.appendChild(o),n-=1,r-=1):(a||c)&&(c||(c=S(l,h.blockTag,h.blockAttributes)),_(c,t),a?e.replaceChild(c,o):(e.insertBefore(c,o),n+=1,r+=1),c=null),s(o)&&y(o,t);return c&&e.appendChild(_(c,t)),e}function T(e,t,n,r){var o,i,a,s=e.nodeType;if(s===I&&e!==n)return T(e.parentNode,e.splitText(t),n,r);if(s===P){if("number"==typeof t&&(t=ts?t.startOffset-=1:t.startOffset===s&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=r,t.endOffset=m(r))),v(n),n.nodeType===I?r.appendData(n.data):d.push(N(n));else if(n.nodeType===P){for(o=d.length;o--;)n.appendChild(d.pop());b(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(a),o=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),o-=1),i={startContainer:e,startOffset:o,endContainer:e,endOffset:o},e.appendChild(N(t)),b(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),X&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function x(e,t){var n,r,o=e.previousSibling,i=e.firstChild,a=e.ownerDocument,d="LI"===e.nodeName;if(!d||i&&/^[OU]L$/.test(i.nodeName))if(o&&h(o,e)){if(!s(o)){if(!d)return;r=S(a,"DIV"),r.appendChild(N(o)),o.appendChild(r)}v(e),n=!s(e),o.appendChild(N(e)),n&&y(o,t),i&&x(i,t)}else d&&(o=S(a,"DIV"),e.insertBefore(o,i),_(o,t))}function k(e){for(var t,n=jt.length;n--;)if(t=jt[n],t._doc===e)return t;return null}function O(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?O(e[n],r):r;return e}function B(e,t){e.nodeType===w&&(e=e.body);var n,r=e.ownerDocument,o=r.defaultView;this._win=o,this._doc=r,this._root=e,this._events={},this._lastSelection=null,ot&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="","onselectionchange"in r?this.addEventListener("selectionchange",this._updatePathOnEvent):(this.addEventListener("keyup",this._updatePathOnEvent),this.addEventListener("mouseup",this._updatePathOnEvent)),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,this._ignoreAllChanges=!1,it?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._restoreSelection=!1,this.addEventListener("blur",L),this.addEventListener("input",A),this.addEventListener("mousedown",A),this.addEventListener("touchstart",A),this.addEventListener("focus",D),this._awaitingPaste=!1,this.addEventListener(Y?"beforecut":"cut",Kt),this.addEventListener("copy",Zt),this.addEventListener(Y?"beforepaste":"paste",Gt),this.addEventListener(X?"keypress":"keydown",kt),this._keyHandlers=Object.create(At),this.setConfig(t),Y&&(o.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,r=this.parentNode,o=this.length-e;return n?r.insertBefore(t,n):r.appendChild(t),o&&this.deleteData(e,o),t}),e.setAttribute("contenteditable","true");try{r.execCommand("enableObjectResizing",!1,"false"),r.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}jt.push(this),this.setHTML("")}function L(){this._restoreSelection=!0}function A(){this._restoreSelection=!1}function D(){this._restoreSelection&&this.setSelection(this._lastSelection)}function R(e,t,n){var r,o;for(r=t.firstChild;r;r=o){if(o=r.nextSibling,i(r)){if(r.nodeType===I||"BR"===r.nodeName||"IMG"===r.nodeName){n.appendChild(r);continue}}else if(a(r)){n.appendChild(e.createDefaultBlock([R(e,r,e._doc.createDocumentFragment())]));continue}R(e,r,n)}return n}var U=2,P=1,I=3,w=9,F=11,M=1,H=4,W=0,z=1,q=2,K=3,Z="​",G=e.defaultView,j=navigator.userAgent,Q=/iP(?:ad|hone|od)/.test(j),V=/Mac OS X/.test(j),$=/Gecko\//.test(j),Y=/Trident\/[456]\./.test(j),X=!!G.opera,J=/Edge\//.test(j),et=!J&&/WebKit\//.test(j),tt=V?"meta-":"ctrl-",nt=Y||X,rt=Y||et,ot=Y,it="undefined"!=typeof MutationObserver,at=/[^ \t\r\n]/,st=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var dt={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)e=t.previousSibling,e||(t=t.parentNode);if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var lt=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|U|VAR|WBR)$/,ct={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},ht=function(e,t){for(var n=e.childNodes;t&&e.nodeType===P;)e=n[t-1],n=e.childNodes,t=n.length;return e},ft=function(e,t){if(e.nodeType===P){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(z,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(W,r)<1,s=e.compareBoundaryPoints(q,r)>-1;return a&&s},Ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,i=e.endContainer,a=e.endOffset;n.nodeType!==I&&(t=n.childNodes[r],t&&!o(t));)n=t,r=0;if(a)for(;i.nodeType!==I&&(t=i.childNodes[a-1],t&&!o(t));)i=t,a=m(i);else for(;i.nodeType!==I&&(t=i.firstChild,t&&!o(t));)i=t;e.collapsed?(e.setStart(i,a),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(i,a))},Nt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=st.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=st.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},St=function(e,t){var n,r=e.startContainer;return i(r)?n=l(r,t):a(r)?n=r:(n=ht(r,e.startOffset),n=c(n,t)),n&&vt(e,n,!0)?n:null},_t=function(e,t){var n,r,o=e.endContainer;if(i(o))n=l(o,t);else if(a(o))n=o;else{if(n=ft(o,e.endOffset),!n||!p(t,n))for(n=t;r=n.lastChild;)n=r;n=l(n,t)}return n&&vt(e,n,!0)?n:null},yt=new n(null,H|M,function(e){return e.nodeType===I?at.test(e.data):"IMG"===e.nodeName}),Tt=function(e,t){var n,r=e.startContainer,o=e.startOffset;if(yt.root=null,r.nodeType===I){if(o)return!1;n=r}else if(n=ft(r,o),n&&!p(t,n)&&(n=null),!n&&(n=ht(r,o),node.nodeType===I&&node.length))return!1;return yt.currentNode=n,yt.root=St(e,t),!yt.previousNode()},bt=function(e,t){var n,r=e.endContainer,o=e.endOffset;if(yt.root=null,r.nodeType===I){if(n=r.data.length,n&&n>o)return!1;yt.currentNode=r}else yt.currentNode=ht(r,o);return yt.root=_t(e,t),!yt.nextNode()},Et=function(e,t){var n,r=St(e,t),o=_t(e,t);r&&o&&(n=r.parentNode,e.setStart(n,st.call(n.childNodes,r)),n=o.parentNode,e.setEnd(n,st.call(n.childNodes,o)+1))},xt={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},kt=function(e){var t=e.keyCode,n=xt[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),X&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-")),e.shiftKey&&(r+="shift-"),n=r+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,o):1!==n.length||o.collapsed||(this.saveUndoState(o),gt(o,this._root),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},Ot=function(e){return function(t,n){n.preventDefault(),t[e]()}},Bt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Lt=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===I&&(r=r.parentNode),n=r;i(n)&&(!n.textContent||n.textContent===Z);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,st.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),a(n)||(n=l(n,e._root)),_(n,e._root),Ct(t)),r===e._root&&(r=r.firstChild)&&"BR"===r.nodeName&&v(r),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(o){e.didError(o)}},At={enter:function(e,t,n){var r,o,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),un(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||gt(n,a),r=St(n,a),!r||/^T[HD]$/.test(r.nodeName))return ut(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((o=u(r,a,"LI"))&&(r=o),!r.textContent){if(u(r,a,"UL")||u(r,a,"OL"))return e.modifyBlocks(hn,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(on,n)}for(i=tn(e,r,n.startContainer,n.startOffset),Yt(r),Ht(r),_(r,a);i.nodeType===P;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===Z)){d=e._doc.createTextNode(""),C(i,d),i=d;break}for(;d&&d.nodeType===I&&!d.data&&(s=d.nextSibling,s&&"BR"!==s.nodeName);)v(d),d=s;if(!d||"BR"===d.nodeName||d.nodeType===I&&!X)break;i=d}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){var r=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Tt(n,r)){t.preventDefault();var o,i=St(n,r);if(!i)return;if(y(i.parentNode,r),o=l(i,r)){if(!o.isContentEditable)return void v(o);for(E(o,i,n),i=o.parentNode;i!==r&&!i.nextSibling;)i=i.parentNode;i!==r&&(i=i.nextSibling)&&x(i,r),e.setSelection(n)}else if(i){if(u(i,r,"UL")||u(i,r,"OL"))return e.modifyBlocks(hn,n);if(u(i,r,"BLOCKQUOTE"))return e.modifyBlocks(rn,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Lt(e)},0);else t.preventDefault(),gt(n,r),Lt(e,n)},"delete":function(e,t,n){var r,o,i,a,s,d,l=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(bt(n,l)){if(t.preventDefault(),r=St(n,l),!r)return;if(y(r.parentNode,l),o=c(r,l)){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o!==l&&!o.nextSibling;)o=o.parentNode;o!==l&&(o=o.nextSibling)&&x(o,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(i=n.cloneRange(),Nt(n,e._root),a=n.endContainer,s=n.endOffset,a.nodeType===P&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),v(d),Ct(n),void Lt(e,n);e.setSelection(i),setTimeout(function(){Lt(e)},0)}else t.preventDefault(),gt(n,l),Lt(e,n)},tab:function(e,t,n){var r,o,i=e._root;if(e._removeZWS(),n.collapsed&&Tt(n,i))for(r=St(n,i);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(cn,n));break}r=o}},"shift-tab":function(e,t,n){var r,o=e._root;e._removeZWS(),n.collapsed&&Tt(n,o)&&(r=n.startContainer,(u(r,o,"UL")||u(r,o,"OL"))&&(t.preventDefault(),e.modifyBlocks(hn,n)))},space:function(e,t,n){var r,o;e._recordUndoState(n),un(n.startContainer,e._root,e),e._getRangeAndRemoveBookmark(n),r=n.endContainer,o=r.parentNode,n.collapsed&&"A"===o.nodeName&&!r.nextSibling&&n.endOffset===m(r)&&n.setStartAfter(o),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&$&&(At["meta-left"]=function(e,t){t.preventDefault();var n=$t(e);n&&n.modify&&n.modify("move","backward","lineboundary")},At["meta-right"]=function(e,t){t.preventDefault();var n=$t(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),V||(At.pageup=function(e){e.moveCursorToStart()},At.pagedown=function(e){e.moveCursorToEnd()}),At[tt+"b"]=Bt("B"),At[tt+"i"]=Bt("I"),At[tt+"u"]=Bt("U"),At[tt+"shift-7"]=Bt("S"),At[tt+"shift-5"]=Bt("SUB",{tag:"SUP"}),At[tt+"shift-6"]=Bt("SUP",{tag:"SUB"}),At[tt+"shift-8"]=Ot("makeUnorderedList"),At[tt+"shift-9"]=Ot("makeOrderedList"),At[tt+"["]=Ot("decreaseQuoteLevel"),At[tt+"]"]=Ot("increaseQuoteLevel"),At[tt+"y"]=Ot("redo"),At[tt+"z"]=Ot("undo"),At[tt+"shift-z"]=Ot("redo");var Dt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Rt={backgroundColor:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color:"+t})}},color:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ut=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Pt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Rt)r=Rt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ut("B"),EM:Ut("I"),STRIKE:Ut("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+Dt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},It=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/,wt=/^(?:HEAD|META|STYLE)/,Ft=new n(null,H|M,function(){return!0}),Mt=function mn(e,t){var n,r,o,a,s,d,l,c,h,f,u,p,g=e.childNodes;for(n=e;i(n);)n=n.parentNode;for(Ft.root=n,r=0,o=g.length;o>r;r+=1)if(a=g[r],s=a.nodeName,d=a.nodeType,l=Pt[s],d===P){if(c=a.childNodes.length,l)a=l(a,e);else{if(wt.test(s)){e.removeChild(a),r-=1,o-=1;continue}if(!It.test(s)&&!i(a)){r-=1,o+=c-1,e.replaceChild(N(a),a);continue}}c&&mn(a,t||"PRE"===s)}else{if(d===I){if(u=a.data,h=!at.test(u.charAt(0)),f=!at.test(u.charAt(u.length-1)),t||!h&&!f)continue;if(h){for(Ft.currentNode=a;(p=Ft.previousPONode())&&(s=p.nodeName,!("IMG"===s||"#text"===s&&/\S/.test(p.data)));)if(!i(p)){p=null;break}u=u.replace(/^\s+/g,p?" ":"")}if(f){for(Ft.currentNode=a;(p=Ft.nextNode())&&!("IMG"===s||"#text"===s&&/\S/.test(p.data));)if(!i(p)){p=null;break}u=u.replace(/\s+$/g,p?" ":"")}if(u){a.data=u;continue}}e.removeChild(a),r-=1,o-=1}return e},Ht=function vn(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==P||o(t)?t.nodeType!==I||t.data||e.removeChild(t):(vn(t),i(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e){return e.nodeType===P?"BR"===e.nodeName:at.test(e.data)},zt=function(e){for(var t,r=e.parentNode;i(r);)r=r.parentNode;return t=new n(r,M|H,Wt),t.currentNode=e,!!t.nextNode()},qt=function(e,t){var n,r,o,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=zt(a[n]);for(;d--;)r=a[d],o=r.parentNode,o&&(s[d]?i(o)||y(o,t):v(r))},Kt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._root,i=this;this.saveUndoState(n),J||Q||!t?setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0):(Nt(n,o),r.appendChild(gt(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},Zt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");J||Q||!t||(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},Gt=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,h=this;if(!J&&s){for(e.preventDefault(),t=s.length;t--;){if(n=s[t],r=n.type,"text/html"===r)return void n.getAsString(function(e){h.insertHTML(e,!0)});"text/plain"===r&&(c=n),/^image\/.*/.test(r)&&(l=!0)}return void(l?(this.fireEvent("dragover",{dataTransfer:a,preventDefault:function(){d=!0}}),d&&this.fireEvent("drop",{dataTransfer:a})):c&&n.getAsString(function(e){h.insertPlainText(e,!0)}))}if(o=a&&a.types,!J&&o&&(st.call(o,"text/html")>-1||!$&&st.call(o,"text/plain")>-1&&st.call(o,"text/rtf")<0))return e.preventDefault(),void((i=a.getData("text/html"))?this.insertHTML(i,!0):((i=a.getData("text/plain"))||(i=a.getData("text/uri-list")))&&this.insertPlainText(i,!0));this._awaitingPaste=!0;var f=this._doc.body,u=this.getSelection(),p=u.startContainer,g=u.startOffset,m=u.endContainer,C=u.endOffset,N=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(N),u.selectNodeContents(N),this.setSelection(u),setTimeout(function(){try{h._awaitingPaste=!1;for(var e,t,n="",r=N;N=r;)r=N.nextSibling,v(N),e=N.firstChild,e&&e===N.lastChild&&"DIV"===e.nodeName&&(N=e),n+=N.innerHTML;t=h._createRange(p,g,m,C),h.setSelection(t),n&&h.insertHTML(n,!0)}catch(o){h.didError(o)}},0)},jt=[],Qt=B.prototype;Qt.setConfig=function(e){return e=O({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},Qt.createElement=function(e,t,n){return S(this._doc,e,t,n)},Qt.createDefaultBlock=function(e){var t=this._config;return _(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},Qt.didError=function(e){console.log(e)},Qt.getDocument=function(){return this._doc},Qt.getRoot=function(){return this._root},Qt.modifyDocument=function(e){this._ignoreAllChanges=!0,this._mutation&&this._mutation.disconnect(),e(),this._ignoreAllChanges=!1,this._mutation&&this._mutation.observe(this._root,{childList:!0,attributes:!0,characterData:!0,subtree:!0})};var Vt={pathChange:1,select:1,input:1,undoStateChange:1};Qt.fireEvent=function(e,t){var n,r,o=this._events[e];if(o)for(t||(t={}),t.type!==e&&(t.type=e),o=o.slice(),n=o.length;n--;){r=o[n];try{r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(i){i.details="Squire: fireEvent error. Event type: "+e,this.didError(i)}}return this},Qt.destroy=function(){var e,t=jt.length,n=this._events;for(e in n)this.removeEventListener(e);for(this._mutation&&this._mutation.disconnect();t--;)jt[t]===this&&jt.splice(t,1)},Qt.handleEvent=function(e){this.fireEvent(e.type,e)},Qt.addEventListener=function(e,t){var n=this._events[e],r=this._root;return t?(n||(n=this._events[e]=[],Vt[e]||("selectionchange"===e&&(r=this._doc),r.addEventListener(e,this,!0))),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Qt.removeEventListener=function(e,t){var n,r=this._events[e],o=this._root;if(r){if(t)for(n=r.length;n--;)r[n]===t&&r.splice(n,1);else r.length=0;r.length||(delete this._events[e],Vt[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},Qt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Qt.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,r=e.getBoundingClientRect();return r&&!r.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=Z,ut(e,t),r=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),b(n,{startContainer:e.startContainer,endContainer:e.endContainer,startOffset:e.startOffset,endOffset:e.endOffset})),r},Qt._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return Ct(n),this.setSelection(n),this},Qt.moveCursorToStart=function(){return this._moveCursorTo(!0)},Qt.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var $t=function(e){return e._win.getSelection()||null};Qt.setSelection=function(e){if(e){this._restoreSelection=!1,this._lastSelection=e,Q&&this._win.focus();var t=$t(this);t&&(t.removeAllRanges(),t.addRange(e))}return this},Qt.getSelection=function(){var e,t,n,r=$t(this),i=this._root;return r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&o(t)&&e.setStartBefore(t),n&&o(n)&&e.setEndBefore(n)),e&&p(i,e.commonAncestorContainer)?this._lastSelection=e:e=this._lastSelection,e||(e=this._createRange(i.firstChild,0)),e},Qt.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,H|M,function(e){return vt(t,e,!0)}),o=t.startContainer,a=t.endContainer,s=r.currentNode=o,d="",l=!1;for(r.filter(s)||(s=r.nextNode());s;)s.nodeType===I?(e=s.data,e&&/\S/.test(e)&&(s===a&&(e=e.slice(0,t.endOffset)),s===o&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===s.nodeName||l&&!i(s))&&(d+="\n",l=!1),s=r.nextNode();return d},Qt.getPath=function(){return this._path};var Yt=function(e){for(var t,r,o,a=new n(e,H,function(){return!0},!1);r=a.nextNode();)for(;(o=r.data.indexOf(Z))>-1;){if(1===r.length){do t=r.parentNode,t.removeChild(r),r=t,a.currentNode=t;while(i(r)&&!m(r));break}r.deleteData(o,1)}};Qt._didAddZWS=function(){this._hasZWS=!0},Qt._removeZWS=function(){this._hasZWS&&(Yt(this._root),this._hasZWS=!1)},Qt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?g(o,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},Qt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Qt.focus=function(){return this._root.focus(),this},Qt.blur=function(){return this._root.blur(),this};var Xt="squire-selection-start",Jt="squire-selection-end";Qt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Xt,type:"hidden"}),r=this.createElement("INPUT",{id:Jt,type:"hidden"});ut(e,n),e.collapse(!1),ut(e,r),n.compareDocumentPosition(r)&U&&(n.id=Jt,r.id=Xt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Qt._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+Xt),r=t.querySelector("#"+Jt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:st.call(i.childNodes,n),endOffset:st.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),b(i,s),i!==a&&b(a,s),e||(e=this._doc.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,o&&(i=e.startContainer,i.nodeType===I&&(a=i.childNodes[e.startOffset],a&&a.nodeType===I||(a=i.childNodes[e.startOffset-1]),a&&a.nodeType===I&&(e.setStart(a,0),e.collapse(!0))))}return e||null},Qt._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},Qt._docWasChanged=function(){if(!this._ignoreAllChanges){if(it&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},Qt._recordUndoState=function(e){if(!this._isInUndoState){var t=this._undoIndex+=1,n=this._undoStack;te+1&&this._isInUndoState){this._undoIndex+=1,this._setHTML(this._undoStack[this._undoIndex]);var n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:t>e+2}),this.fireEvent("input")}return this},Qt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;!r.collapsed&&r.startContainer.nodeType===I&&r.startOffset===r.startContainer.length&&r.startContainer.nextSibling&&r.setStartBefore(r.startContainer.nextSibling),!r.collapsed&&r.endContainer.nodeType===I&&0===r.endOffset&&r.endContainer.previousSibling&&r.setEndAfter(r.endContainer.previousSibling);var o,i,a=this._root,s=r.commonAncestorContainer;if(u(s,a,e,t))return!0;if(s.nodeType===I)return!1;o=new n(s,H,function(e){return vt(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},Qt.getFontInfo=function(e){var n,r,o,i={color:t,backgroundColor:t,family:t,size:t},a=0;if(!e&&!(e=this.getSelection()))return i;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===I)for(n.nodeType===I&&(n=n.parentNode);4>a&&n;)(r=n.style)&&(!i.color&&(o=r.color)&&(i.color=o,a+=1),!i.backgroundColor&&(o=r.backgroundColor)&&(i.backgroundColor=o,a+=1),!i.family&&(o=r.fontFamily)&&(i.family=o,a+=1),!i.size&&(o=r.fontSize)&&(i.size=o,a+=1)),n=n.parentNode;return i},Qt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,h,f=this._root;if(r.collapsed)o=_(this.createElement(e,t),f),ut(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{if(i=new n(r.commonAncestorContainer,H|M,function(e){return(e.nodeType===I||"BR"===e.nodeName||"IMG"===e.nodeName)&&vt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,i.filter(a)||(a=i.nextNode(),d=0),!a)return r;do c=i.currentNode,h=!u(c,f,e,t),h&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),s===a&&(s=c,l-=d),a=c,d=0),o=this.createElement(e,t),C(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==I&&(c.nodeType===I?(s=c,l=c.length):(s=c.parentNode,l=1)),r=this._createRange(a,d,s,l) }return r},Qt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var o,a=this._doc;n.collapsed&&(rt?(o=a.createTextNode(Z),this._didAddZWS()):o=a.createTextNode(""),ut(n,o));for(var s=n.commonAncestorContainer;i(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!vt(n,e,!1)){var r,o,i=e.nodeType===I;if(!vt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===c&&h!==e.length&&u.push([t,e.splitText(h)]),e===d&&l&&(e.splitText(l),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(r){return vt(n,r,!0)&&f(r,e,t)});r||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,N(e))}),this._getRangeAndRemoveBookmark(n),o&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return b(s,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},Qt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),it||this._docWasChanged(),this):void 0};var en={DT:"DD",DD:"DT",LI:"LI"},tn=function(e,t,n,r){var o=en[t.nodeName],i=null,a=T(n,r,t.parentNode,e._root),s=e._config;return o||(o=s.blockTag,i=s.blockAttributes),f(a,o,i)||(t=S(a.ownerDocument,o,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(N(a)),a=t),a};Qt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,o=St(n,r),i=_t(n,r);if(o&&i)do if(e(o)||o===i)break;while(o=c(o,r));return t&&(this.setSelection(n),this._updatePath(n,!0),it||this._docWasChanged()),this},Qt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t);var n,r=this._root;return Et(t,r),Nt(t,r),n=pt(t,r,r),ut(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],C(s,N(s));y(i,this._root),C(o,i)}return e},cn=function(e){var t,n,r,o,i,a,d=e.querySelectorAll("LI"),l=this._config.tagAttributes,c=l.li;for(t=0,n=d.length;n>t;t+=1)r=d[t],s(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||(a=l[o.toLowerCase()],C(r,this.createElement("LI",c,[i=this.createElement(o,a)]))),i.appendChild(r));return e},hn=function(e){var t=this._root,n=e.querySelectorAll("LI");return Array.prototype.filter.call(n,function(e){return!s(e.firstChild)}).forEach(function(n){var r,o=n.parentNode,i=o.parentNode,a=n.firstChild,d=a;for(n.previousSibling&&(o=T(o,n,i,t));d&&(r=d.nextSibling,!s(d));)i.insertBefore(d,o),d=r;for("LI"===i.nodeName&&a.previousSibling&&T(i,a,i.parentNode,t);n!==e&&!n.childNodes.length;)o=n.parentNode,o.removeChild(n),n=o},this),y(e,t),e};Qt._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},Qt.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},Qt._getHTML=function(){return this._root.innerHTML},Qt._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do _(n,t);while(n=c(n,t));this._ignoreChange=!0},Qt.getHTML=function(e){var t,n,r,o,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),nt)for(t=this._root,n=t;n=c(n,t);)n.textContent||n.querySelector("BR")||(r=this.createElement("BR"),n.appendChild(r),s.push(r));if(o=this._getHTML().replace(/\u200B/g,""),nt)for(i=s.length;i--;)v(s[i]);return a&&this._getRangeAndRemoveBookmark(a),o},Qt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),o=this._root;r.innerHTML=e,n.appendChild(N(r)),Mt(n),qt(n,o),y(n,o);for(var i=n;i=c(i,o);)_(i,o);for(this._ignoreChange=!0;t=o.lastChild;)o.removeChild(t);o.appendChild(n),_(o,o),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var a=this._getRangeAndRemoveBookmark()||this._createRange(o.firstChild,0);return this.saveUndoState(a),this._lastSelection=a,this._updatePath(a,!0),this},Qt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),i(e))ut(t,e),t.setStartAfter(e);else{for(var n,r,o=this._root,a=St(t,o)||o;a!==o&&!a.nextSibling;)a=a.parentNode;a!==o&&(n=a.parentNode,r=T(n,a.nextSibling,o,o)),r?o.insertBefore(e,r):(o.appendChild(e),r=this.createDefaultBlock(),o.appendChild(r)),t.setStart(r,0),t.setEnd(r,0),Ct(t)}return this.focus(),this.setSelection(t),this._updatePath(t),it||this._docWasChanged(),this},Qt.insertImage=function(e,t){var n=this.createElement("IMG",O({src:e},t));return this.insertElement(n),n};var fn=/\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i,un=function(e,t,r){for(var o,i,a,s,d,l,c,h=e.ownerDocument,f=new n(e,H,function(e){return!u(e,t,"A")},!1),p=r._config.tagAttributes.a;o=f.nextNode();)for(i=o.data,a=o.parentNode;s=fn.exec(i);)d=s.index,l=d+s[0].length,d&&(c=h.createTextNode(i.slice(0,d)),a.insertBefore(c,o)),c=r.createElement("A",O({href:s[1]?/^(?:ht|f)tps?:/.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[2]},p)),c.textContent=i.slice(d,l),a.insertBefore(c,o),o.data=i=i.slice(l)};Qt.insertHTML=function(e,t){var n=this.getSelection(),r=this._doc.createDocumentFragment(),o=this.createElement("DIV");o.innerHTML=e,r.appendChild(N(o)),this.saveUndoState(n);try{var i=this._root,a=r,s={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1};for(un(r,r,this),Mt(r),qt(r,null),Ht(r),r.normalize();a=c(a,r);)_(a,null);t&&this.fireEvent("willPaste",s),s.defaultPrevented||(mt(n,s.fragment,i),it||this._docWasChanged(),n.collapse(!1),this._ensureBottomLine()),this.setSelection(n),this._updatePath(n,!0)}catch(d){this.didError(d)}return this};var pn=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};Qt.insertPlainText=function(e,t){var n,r,o,i,a=e.split("\n"),s=this._config,d=s.blockTag,l=s.blockAttributes,c="",h="<"+d;for(n in l)h+=" "+n+'="'+pn(l[n])+'"';for(h+=">",r=0,o=a.length;o>r;r+=1)i=a[r],i=pn(i).replace(/ (?= )/g," "),r&&o>r+1&&(i=h+(i||"
")+c),a[r]=i;return this.insertHTML(a.join(""),t)};var gn=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Qt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.appendChild(this._doc.createTextNode(e)),t.appendChild(n)}return this},Qt.bold=gn("changeFormat",{tag:"B"}),Qt.italic=gn("changeFormat",{tag:"I"}),Qt.underline=gn("changeFormat",{tag:"U"}),Qt.strikethrough=gn("changeFormat",{tag:"S"}),Qt.subscript=gn("changeFormat",{tag:"SUB"},{tag:"SUP"}),Qt.superscript=gn("changeFormat",{tag:"SUP"},{tag:"SUB"}),Qt.removeBold=gn("changeFormat",null,{tag:"B"}),Qt.removeItalic=gn("changeFormat",null,{tag:"I"}),Qt.removeUnderline=gn("changeFormat",null,{tag:"U"}),Qt.removeStrikethrough=gn("changeFormat",null,{tag:"S"}),Qt.removeSubscript=gn("changeFormat",null,{tag:"SUB"}),Qt.removeSuperscript=gn("changeFormat",null,{tag:"SUP"}),Qt.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;ut(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),O(t,this._config.tagAttributes.a),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},Qt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Qt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Qt.setFontSize=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}},{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},Qt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Qt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Qt.setTextAlignment=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/align/.test(e)}).join(" ")+" align-"+e).trim(),t.style.textAlign=e},!0),this.focus()},Qt.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},Qt.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=this._root,n=e.commonAncestorContainer;n&&!a(n);)n=n.parentNode;if(n||(Et(e,t),n=t),n.nodeType===I)return this;this.saveUndoState(e),Nt(e,n);for(var r,o,i,s=n.ownerDocument,d=e.startContainer,l=e.startOffset,c=e.endContainer,h=e.endOffset,f=s.createDocumentFragment(),u=s.createDocumentFragment(),p=T(c,h,n,t),g=T(d,l,n,t);g!==p;)r=g.nextSibling,f.appendChild(g),g=r;return R(this,f,u),u.normalize(),g=u.firstChild,r=u.lastChild,i=n.childNodes,g?(n.insertBefore(u,p),l=st.call(i,g),h=st.call(i,r)+1):(l=st.call(i,p),h=l),o={startContainer:n,startOffset:l,endContainer:n,endOffset:h},b(n,o),e.setStart(o.startContainer,o.startOffset),e.setEnd(o.endContainer,o.endOffset),Ct(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},Qt.increaseQuoteLevel=gn("modifyBlocks",nn),Qt.decreaseQuoteLevel=gn("modifyBlocks",rn),Qt.makeUnorderedList=gn("modifyBlocks",sn),Qt.makeOrderedList=gn("modifyBlocks",dn),Qt.removeList=gn("modifyBlocks",ln),Qt.increaseListLevel=gn("modifyBlocks",cn),Qt.decreaseListLevel=gn("modifyBlocks",hn),"object"==typeof exports?module.exports=B:"function"==typeof define&&define.amd?define(function(){return B}):(G.Squire=B,top!==G&&"true"===e.documentElement.getAttribute("data-squireinit")&&(G.editor=new B(e),G.onEditorLoad&&(G.onEditorLoad(G.editor),G.onEditorLoad=null)))}(document); \ No newline at end of file