From 32fa092a796d8d7a24abbee86b2b6851804f8b43 Mon Sep 17 00:00:00 2001 From: Andy Kauffman Date: Wed, 6 Jul 2016 13:27:22 -0400 Subject: [PATCH 1/6] Path contains format values Add values of font size, font face, and color to the path. This allows us to distinguish path changes to different formats. --- build/squire-raw.js | 27 +++++++++++++++++++++++---- build/squire.js | 5 +++-- source/Clean.js | 8 ++++---- source/Constants.js | 5 +++++ source/Node.js | 14 ++++++++++++++ 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 7187d4e..e050489 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -17,6 +17,11 @@ var START_TO_END = 1; // Range.START_TO_END var END_TO_END = 2; // Range.END_TO_END var END_TO_START = 3; // Range.END_TO_START +var HIGHLIGHT_CLASS = 'highlight'; +var COLOUR_CLASS = 'colour'; +var FONT_FAMILY_CLASS = 'font'; +var FONT_SIZE_CLASS = 'size'; + var ZWS = '\u200B'; var win = doc.defaultView; @@ -284,6 +289,20 @@ function getPath ( node, root ) { if ( dir = node.dir ) { path += '[dir=' + dir + ']'; } + if( classNames ) { + if ( indexOf.call( classNames, HIGHLIGHT_CLASS ) > -1 ) { + path += '[backgroundColor=' + node.style.backgroundColor.replace(/ /g,'') + ']'; + } + if ( indexOf.call( classNames, COLOUR_CLASS ) > -1 ) { + path += '[color=' + node.style.color.replace(/ /g,'') + ']'; + } + if ( indexOf.call( classNames, FONT_FAMILY_CLASS ) > -1 ) { + path += '[fontFamily=' + node.style.fontFamily.replace(/ /g,'') + ']'; + } + if ( indexOf.call( classNames, FONT_SIZE_CLASS ) > -1 ) { + path += '[fontSize=' + node.style.fontSize + ']'; + } + } } } return path; @@ -1695,7 +1714,7 @@ var styleToSemantic = { regexp: notWS, replace: function ( doc, colour ) { return createElement( doc, 'SPAN', { - 'class': 'highlight', + 'class': HIGHLIGHT_CLASS, style: 'background-color:' + colour }); } @@ -1704,7 +1723,7 @@ var styleToSemantic = { regexp: notWS, replace: function ( doc, colour ) { return createElement( doc, 'SPAN', { - 'class': 'colour', + 'class': COLOUR_CLASS, style: 'color:' + colour }); } @@ -1725,7 +1744,7 @@ var styleToSemantic = { regexp: notWS, replace: function ( doc, family ) { return createElement( doc, 'SPAN', { - 'class': 'font', + 'class': FONT_FAMILY_CLASS, style: 'font-family:' + family }); } @@ -1734,7 +1753,7 @@ var styleToSemantic = { regexp: notWS, replace: function ( doc, size ) { return createElement( doc, 'SPAN', { - 'class': 'size', + 'class': FONT_SIZE_CLASS, style: 'font-size:' + size }); } diff --git a/build/squire.js b/build/squire.js index 6089df2..12bef72 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1,2 +1,3 @@ -!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 i(e){return e.nodeType===P&&!!ct[e.nodeName]}function o(e){return lt.test(e.nodeName)}function a(e){var t=e.nodeType;return(t===P||t===F)&&!o(e)&&r(e.childNodes,o)}function s(e){var t=e.nodeType;return!(t!==P&&t!==F||o(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!i(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,i,o,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())&&(i=r.split(/\s\s*/),i.sort(),a+=".",a+=i.join(".")),(o=e.dir)&&(a+="[dir="+o+"]"))),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 _(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function N(e,n,r,i){var o,a,s,d,l=e.createElement(n);if(r instanceof Array&&(i=r,r=null),r)for(o in r)a=r[o],a!==t&&l.setAttribute(o,r[o]);if(i)for(s=0,d=i.length;d>s;s+=1)l.appendChild(i[s]);return l}function S(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=O(a).createDefaultBlock(),r?e.replaceChild(n,r):e.appendChild(n),e=n,n=null)),e.nodeType===I)return s;if(o(e)){for(r=e.firstChild;rt&&r&&r.nodeType===I&&!r.data;)e.removeChild(r),r=e.firstChild;r||(rt?(n=a.createTextNode(Z),O(a)._didAddZWS()):n=a.createTextNode(""))}else if(nt){for(;e.nodeType!==I&&!i(e);){if(r=e.firstChild,!r){n=a.createTextNode("");break}e=r}e.nodeType===I?/^ +$/.test(e.data)&&(e.data=""):i(e)&&e.parentNode.insertBefore(a.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=N(a,"BR");(r=e.lastElementChild)&&!o(r);)e=r;if(n)try{e.appendChild(n)}catch(d){O(a).didError({name:"Squire: fixCursor – "+d,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return s}function y(e,t){var n,r,i,a,d=e.childNodes,l=e.ownerDocument,c=null,h=O(l)._config;for(n=0,r=d.length;r>n;n+=1)i=d[n],a="BR"===i.nodeName,!a&&o(i)?(c||(c=N(l,h.blockTag,h.blockAttributes)),c.appendChild(i),n-=1,r-=1):(a||c)&&(c||(c=N(l,h.blockTag,h.blockAttributes)),S(c,t),a?e.replaceChild(c,i):(e.insertBefore(c,i),n+=1,r+=1),c=null),s(i)&&y(i,t);return c&&e.appendChild(S(c,t)),e}function T(e,t,n,r){var i,o,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));else if(n.nodeType===P){for(i=d.length;i--;)n.appendChild(d.pop());E(n,t)}}function b(e,t,n){for(var r,i,o,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(a),i=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),i-=1),o={startContainer:e,startOffset:i,endContainer:e,endOffset:i},e.appendChild(_(t)),E(e,o),n.setStart(o.startContainer,o.startOffset),n.collapse(!0),X&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function x(e,t){var n,r,i=e.previousSibling,o=e.firstChild,a=e.ownerDocument,d="LI"===e.nodeName;if(!d||o&&/^[OU]L$/.test(o.nodeName))if(i&&h(i,e)){if(!s(i)){if(!d)return;r=N(a,"DIV"),r.appendChild(_(i)),i.appendChild(r)}v(e),n=!s(e),i.appendChild(_(e)),n&&y(i,t),o&&x(o,t)}else d&&(i=N(a,"DIV"),e.insertBefore(i,o),S(i,t))}function O(e){for(var t,n=Vt.length;n--;)if(t=Vt[n],t._doc===e)return t;return null}function k(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?k(e[n],r):r;return e}function L(e,t){e.nodeType===w&&(e=e.body);var n,r=e.ownerDocument,i=r.defaultView;this._win=i,this._doc=r,this._root=e,this._events={},this._isFocused=!1,this._lastSelection=null,it&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"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,ot?(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",A),this.addEventListener("mousedown",B),this.addEventListener("touchstart",B),this.addEventListener("focus",D),this._awaitingPaste=!1,this.addEventListener(Y?"beforecut":"cut",Zt),this.addEventListener("copy",Gt),this.addEventListener(Y?"beforepaste":"paste",jt),this.addEventListener("drop",Qt),this.addEventListener(X?"keypress":"keydown",Ot),this._keyHandlers=Object.create(Bt),this.setConfig(t),Y&&(i.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,r=this.parentNode,i=this.length-e;return n?r.insertBefore(t,n):r.appendChild(t),i&&this.deleteData(e,i),t}),e.setAttribute("contenteditable","true");try{r.execCommand("enableObjectResizing",!1,"false"),r.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}Vt.push(this),this.setHTML("")}function A(){this._restoreSelection=!0}function B(){this._restoreSelection=!1}function D(){this._restoreSelection&&this.setSelection(this._lastSelection)}function R(e,t,n){var r,i;for(r=t.firstChild;r;r=i){if(i=r.nextSibling,o(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,it=Y,ot="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,i=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&&i(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,i=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&&i(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,i=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&&i(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,o=e.compareBoundaryPoints(z,r)<1;return!i&&!o}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,o=e.endContainer,a=e.endOffset;n.nodeType!==I&&(t=n.childNodes[r],t&&!i(t));)n=t,r=0;if(a)for(;o.nodeType!==I&&(t=o.childNodes[a-1],t&&!i(t));)o=t,a=m(o);else for(;o.nodeType!==I&&(t=o.firstChild,t&&!i(t));)o=t;e.collapsed?(e.setStart(o,a),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,a))},_t=function(e,t){var n,r=e.startContainer,i=e.startOffset,o=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!i;)n=r.parentNode,i=st.call(n.childNodes,r),r=n;for(;o!==t&&a===m(o);)n=o.parentNode,a=st.call(n.childNodes,o)+1,o=n;e.setStart(r,i),e.setEnd(o,a)},Nt=function(e,t){var n,r=e.startContainer;return o(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},St=function(e,t){var n,r,i=e.endContainer;if(o(i))n=l(i,t);else if(a(i))n=i;else{if(n=ft(i,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,i=e.startOffset;if(yt.root=null,r.nodeType===I){if(i)return!1;n=r}else if(n=ft(r,i),n&&!p(t,n)&&(n=null),!n&&(n=ht(r,i),n.nodeType===I&&n.length))return!1;return yt.currentNode=n,yt.root=Nt(e,t),!yt.previousNode()},Et=function(e,t){var n,r=e.endContainer,i=e.endOffset;if(yt.root=null,r.nodeType===I){if(n=r.data.length,n&&n>i)return!1;yt.currentNode=r}else yt.currentNode=ht(r,i);return yt.root=St(e,t),!yt.nextNode()},bt=function(e,t){var n,r=Nt(e,t),i=St(e,t);r&&i&&(n=r.parentNode,e.setStart(n,st.call(n.childNodes,r)),n=i.parentNode,e.setEnd(n,st.call(n.childNodes,i)+1))},xt={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},Ot=function(e){var t=e.keyCode,n=xt[t],r="",i=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,i):1!==n.length||i.collapsed||(this.saveUndoState(i),gt(i,this._root),this._ensureBottomLine(),this.setSelection(i),this._updatePath(i,!0)))},kt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Lt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var i=n.getSelection();n.hasFormat(e,null,i)?n.changeFormat(null,{tag:e},i):n.changeFormat({tag:e},t,i)}},At=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===I&&(r=r.parentNode),n=r;o(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)),S(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(i){e.didError(i)}},Bt={enter:function(e,t,n){var r,i,o,a=e._root;if(t.preventDefault(),e._recordUndoState(n),gn(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||gt(n,a),r=Nt(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((i=u(r,a,"LI"))&&(r=i),!r.textContent){if(u(r,a,"UL")||u(r,a,"OL"))return e.modifyBlocks(un,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(sn,n)}for(o=rn(e,r,n.startContainer,n.startOffset),Jt(r),Wt(r),S(r,a);o.nodeType===P;){var s,d=o.firstChild;if("A"===o.nodeName&&(!o.textContent||o.textContent===Z)){d=e._doc.createTextNode(""),C(o,d),o=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;o=d}n=e._createRange(o,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 i,o=Nt(n,r);if(!o)return;if(y(o.parentNode,r),i=l(o,r)){if(!i.isContentEditable)return void v(i);for(b(i,o,n),o=i.parentNode;o!==r&&!o.nextSibling;)o=o.parentNode;o!==r&&(o=o.nextSibling)&&x(o,r),e.setSelection(n)}else if(o){if(u(o,r,"UL")||u(o,r,"OL"))return e.modifyBlocks(un,n);if(u(o,r,"BLOCKQUOTE"))return e.modifyBlocks(an,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){At(e)},0);else t.preventDefault(),gt(n,r),At(e,n)},"delete":function(e,t,n){var r,i,o,a,s,d,l=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Et(n,l)){if(t.preventDefault(),r=Nt(n,l),!r)return;if(y(r.parentNode,l),i=c(r,l)){if(!i.isContentEditable)return void v(i);for(b(r,i,n),i=r.parentNode;i!==l&&!i.nextSibling;)i=i.parentNode;i!==l&&(i=i.nextSibling)&&x(i,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(o=n.cloneRange(),_t(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 At(e,n);e.setSelection(o),setTimeout(function(){At(e)},0)}else t.preventDefault(),gt(n,l),At(e,n)},tab:function(e,t,n){var r,i,o=e._root;if(e._removeZWS(),n.collapsed&&Tt(n,o))for(r=Nt(n,o);i=r.parentNode;){if("UL"===i.nodeName||"OL"===i.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(fn,n));break}r=i}},"shift-tab":function(e,t,n){var r,i=e._root;e._removeZWS(),n.collapsed&&Tt(n,i)&&(r=n.startContainer,(u(r,i,"UL")||u(r,i,"OL"))&&(t.preventDefault(),e.modifyBlocks(un,n)))},space:function(e,t,n){var r,i;e._recordUndoState(n),gn(n.startContainer,e._root,e),e._getRangeAndRemoveBookmark(n),r=n.endContainer,i=r.parentNode,n.collapsed&&"A"===i.nodeName&&!r.nextSibling&&n.endOffset===m(r)&&n.setStartAfter(i),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&$&&(Bt["meta-left"]=function(e,t){t.preventDefault();var n=Xt(e);n&&n.modify&&n.modify("move","backward","lineboundary")},Bt["meta-right"]=function(e,t){t.preventDefault();var n=Xt(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),V||(Bt.pageup=function(e){e.moveCursorToStart()},Bt.pagedown=function(e){e.moveCursorToEnd()}),Bt[tt+"b"]=Lt("B"),Bt[tt+"i"]=Lt("I"),Bt[tt+"u"]=Lt("U"),Bt[tt+"shift-7"]=Lt("S"),Bt[tt+"shift-5"]=Lt("SUB",{tag:"SUP"}),Bt[tt+"shift-6"]=Lt("SUP",{tag:"SUB"}),Bt[tt+"shift-8"]=kt("makeUnorderedList"),Bt[tt+"shift-9"]=kt("makeOrderedList"),Bt[tt+"["]=kt("decreaseQuoteLevel"),Bt[tt+"]"]=kt("increaseQuoteLevel"),Bt[tt+"y"]=kt("redo"),Bt[tt+"z"]=kt("undo"),Bt[tt+"shift-z"]=kt("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 N(e,"SPAN",{"class":"highlight",style:"background-color:"+t})}},color:{regexp:at,replace:function(e,t){return N(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return N(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return N(e,"I")}},fontFamily:{regexp:at,replace:function(e,t){return N(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:at,replace:function(e,t){return N(e,"SPAN",{"class":"size",style:"font-size:"+t})}},textDecoration:{regexp:/^underline/i,replace:function(e){return N(e,"U")}}},Ut=function(e){return function(t,n){var r=N(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(_(t)),r}},Pt=function(e,t){var n,r,i,o,a,s,d=e.style,l=e.ownerDocument;for(n in Rt)r=Rt[n],i=d[n],i&&r.regexp.test(i)&&(s=r.replace(l,i),a||(a=s),o&&o.appendChild(s),o=s,e.style[n]="");return a&&(o.appendChild(_(e)),"SPAN"===e.nodeName?t.replaceChild(a,e):e.appendChild(a)),o||e},It={P:Pt,SPAN:Pt,STRONG:Ut("B"),EM:Ut("I"),INS:Ut("U"),STRIKE:Ut("S"),FONT:function(e,t){var n,r,i,o,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=N(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,o=n),d&&(r=N(c,"SPAN",{"class":"size",style:"font-size:"+Dt[d]+"px"}),a||(a=r),o&&o.appendChild(r),o=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),i=N(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=i),o&&o.appendChild(i),o=i),a||(a=o=N(c,"SPAN")),t.replaceChild(a,e),o.appendChild(_(e)),o},TT:function(e,t){var n=N(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(_(e)),n}},wt=/^(?: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)$/,Ft=/^(?:HEAD|META|STYLE)/,Mt=new n(null,H|M,function(){return!0}),Ht=function Cn(e,t){var n,r,i,a,s,d,l,c,h,f,u,p,g=e.childNodes;for(n=e;o(n);)n=n.parentNode;for(Mt.root=n,r=0,i=g.length;i>r;r+=1)if(a=g[r],s=a.nodeName,d=a.nodeType,l=It[s],d===P){if(c=a.childNodes.length,l)a=l(a,e);else{if(Ft.test(s)){e.removeChild(a),r-=1,i-=1;continue}if(!wt.test(s)&&!o(a)){r-=1,i+=c-1,e.replaceChild(_(a),a);continue}}c&&Cn(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(Mt.currentNode=a;(p=Mt.previousPONode())&&(s=p.nodeName,!("IMG"===s||"#text"===s&&/\S/.test(p.data)));)if(!o(p)){p=null;break}u=u.replace(/^\s+/g,p?" ":"")}if(f){for(Mt.currentNode=a;(p=Mt.nextNode())&&!("IMG"===s||"#text"===s&&/\S/.test(p.data));)if(!o(p)){p=null;break}u=u.replace(/\s+$/g,p?" ":"")}if(u){a.data=u;continue}}e.removeChild(a),r-=1,i-=1}return e},Wt=function _n(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==P||i(t)?t.nodeType!==I||t.data||e.removeChild(t):(_n(t),o(t)&&!t.firstChild&&e.removeChild(t))},zt=function(e){return e.nodeType===P?"BR"===e.nodeName:at.test(e.data)},qt=function(e){for(var t,r=e.parentNode;o(r);)r=r.parentNode;return t=new n(r,M|H,zt),t.currentNode=e,!!t.nextNode()},Kt=function(e,t){var n,r,i,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=qt(a[n]);for(;d--;)r=a[d],i=r.parentNode,i&&(s[d]?o(i)||y(i,t):v(r))},Zt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),i=this._root,o=this;this.saveUndoState(n),J||Q||!t?setTimeout(function(){try{o._ensureBottomLine()}catch(e){o.didError(e)}},0):(_t(n,i),r.appendChild(gt(n,i)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},Gt=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())},jt=function(e){var t,n,r,i,o,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(i=a&&a.types,!J&&i&&(st.call(i,"text/html")>-1||!$&&st.call(i,"text/plain")>-1&&st.call(i,"text/rtf")<0))return e.preventDefault(),void((o=a.getData("text/html"))?this.insertHTML(o,!0):((o=a.getData("text/plain"))||(o=a.getData("text/uri-list")))&&this.insertPlainText(o,!0));this._awaitingPaste=!0;var f=this._doc.body,u=this.getSelection(),p=u.startContainer,g=u.startOffset,m=u.endContainer,C=u.endOffset,_=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(_),u.selectNodeContents(_),this.setSelection(u),setTimeout(function(){try{h._awaitingPaste=!1;for(var e,t,n="",r=_;_=r;)r=_.nextSibling,v(_),e=_.firstChild,e&&e===_.lastChild&&"DIV"===e.nodeName&&(_=e),n+=_.innerHTML;t=h._createRange(p,g,m,C),h.setSelection(t),n&&h.insertHTML(n,!0)}catch(i){h.didError(i)}},0)},Qt=function(e){for(var t=e.dataTransfer.types,n=t.length,r=!1,i=!1;n--;)switch(t[n]){case"text/plain":r=!0;break;case"text/html":i=!0;break;default:return}(i||r)&&this.saveUndoState()},Vt=[],$t=L.prototype;$t.setConfig=function(e){return e=k({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},undo:{documentSizeThreshold:-1,undoLimit:-1}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},$t.createElement=function(e,t,n){return N(this._doc,e,t,n)},$t.createDefaultBlock=function(e){var t=this._config;return S(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},$t.didError=function(e){console.log(e)},$t.getDocument=function(){return this._doc},$t.getRoot=function(){return this._root},$t.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 Yt={pathChange:1,select:1,input:1,undoStateChange:1};$t.fireEvent=function(e,t){var n,r,i,o=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=p(this._root,this._doc.activeElement),"focus"===e){if(!n||this._isFocused)return this;this._isFocused=!0}else{if(n||!this._isFocused)return this;this._isFocused=!1}if(o)for(t||(t={}),t.type!==e&&(t.type=e),o=o.slice(),r=o.length;r--;){i=o[r];try{i.handleEvent?i.handleEvent(t):i.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},$t.destroy=function(){var e,t=Vt.length,n=this._events;for(e in n)this.removeEventListener(e);for(this._mutation&&this._mutation.disconnect();t--;)Vt[t]===this&&Vt.splice(t,1);this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0},$t.handleEvent=function(e){this.fireEvent(e.type,e)},$t.addEventListener=function(e,t){var n=this._events[e],r=this._root;return t?(n||(n=this._events[e]=[],Yt[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)},$t.removeEventListener=function(e,t){var n,r=this._events[e],i=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],Yt[e]||("selectionchange"===e&&(i=this._doc),i.removeEventListener(e,this,!0)))}return this},$t._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var i=this._doc.createRange();return i.setStart(e,t),n?i.setEnd(n,r):i.setEnd(e,t),i},$t.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),E(n,{startContainer:e.startContainer,endContainer:e.endContainer,startOffset:e.startOffset,endOffset:e.endOffset})),r},$t._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return Ct(n),this.setSelection(n),this},$t.moveCursorToStart=function(){return this._moveCursorTo(!0)},$t.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var Xt=function(e){return e._win.getSelection()||null};$t.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused){Q&&this._win.focus();var t=Xt(this);t&&(t.removeAllRanges(),t.addRange(e))}else A.call(this);return this},$t.getSelection=function(){var e,t,n,r=Xt(this),o=this._root;return r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&i(t)&&e.setStartBefore(t),n&&i(n)&&e.setEndBefore(n)),e&&p(o,e.commonAncestorContainer)?this._lastSelection=e:e=this._lastSelection,e||(e=this._createRange(o.firstChild,0)),e},$t.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,H|M,function(e){return vt(t,e,!0)}),i=t.startContainer,a=t.endContainer,s=r.currentNode=i,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===i&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===s.nodeName||l&&!o(s))&&(d+="\n",l=!1),s=r.nextNode();return d},$t.getPath=function(){return this._path};var Jt=function(e){for(var t,r,i,a=new n(e,H,function(){return!0},!1);r=a.nextNode();)for(;(i=r.data.indexOf(Z))>-1;){if(1===r.length){do t=r.parentNode,t.removeChild(r),r=t,a.currentNode=t;while(o(r)&&!m(r));break}r.deleteData(i,1)}};$t._didAddZWS=function(){this._hasZWS=!0},$t._removeZWS=function(){this._hasZWS&&(Jt(this._root),this._hasZWS=!1)},$t._updatePath=function(e,t){var n,r=e.startContainer,i=e.endContainer;(t||r!==this._lastAnchorNode||i!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=i,n=r&&i?r===i?g(i,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},$t._updatePathOnEvent=function(){var e=this;e._willUpdatePath||(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1,e._updatePath(e.getSelection())},0))},$t.focus=function(){return this._root.focus(),this},$t.blur=function(){return this._root.blur(),this};var en="squire-selection-start",tn="squire-selection-end";$t._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:en,type:"hidden"}),r=this.createElement("INPUT",{id:tn,type:"hidden"});ut(e,n),e.collapse(!1),ut(e,r),n.compareDocumentPosition(r)&U&&(n.id=tn,r.id=en,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},$t._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+en),r=t.querySelector("#"+tn);if(n&&r){var i,o=n.parentNode,a=r.parentNode,s={startContainer:o,endContainer:a,startOffset:st.call(o.childNodes,n),endOffset:st.call(a.childNodes,r)};o===a&&(s.endOffset-=1),v(n),v(r),E(o,s),o!==a&&E(a,s),e||(e=this._doc.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),i=e.collapsed,i&&(o=e.startContainer,o.nodeType===I&&(a=o.childNodes[e.startOffset],a&&a.nodeType===I||(a=o.childNodes[e.startOffset-1]),a&&a.nodeType===I&&(e.setStart(a,0),e.collapse(!0))))}return e||null},$t._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},$t._docWasChanged=function(){if(!this._ignoreAllChanges){if(ot&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},$t._recordUndoState=function(e){if(!this._isInUndoState){var t,n=this._undoIndex+=1,r=this._undoStack,i=this._config.undo,o=i.documentSizeThreshold,a=i.undoLimit;n-1&&2*t.length>o&&a>-1&&n>a&&(r.splice(0,n-a),n=this._undoIndex=a,this._undoStackLength=a),r[n]=t,this._undoStackLength+=1,this._isInUndoState=!0}},$t.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._isInUndoState||(this._recordUndoState(e),this._getRangeAndRemoveBookmark(e)),this},$t.undo=function(){if(0!==this._undoIndex||!this._isInUndoState){this._recordUndoState(this.getSelection()),this._undoIndex-=1,this._setHTML(this._undoStack[this._undoIndex]);var e=this._getRangeAndRemoveBookmark();e&&this.setSelection(e),this._isInUndoState=!0,this.fireEvent("undoStateChange",{canUndo:0!==this._undoIndex,canRedo:!0}),this.fireEvent("input")}return this},$t.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(t>e+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},$t.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 i,o,a=this._root,s=r.commonAncestorContainer;if(u(s,a,e,t))return!0;if(s.nodeType===I)return!1;i=new n(s,H,function(e){return vt(r,e,!0)},!1);for(var d=!1;o=i.nextNode();){if(!u(o,a,e,t))return!1;d=!0}return d},$t.getFontInfo=function(e){var n,r,i,o={color:t,backgroundColor:t,family:t,size:t},a=0;if(!e&&!(e=this.getSelection()))return o;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===I)for(n.nodeType===I&&(n=n.parentNode);4>a&&n;)(r=n.style)&&(!o.color&&(i=r.color)&&(o.color=i,a+=1),!o.backgroundColor&&(i=r.backgroundColor)&&(o.backgroundColor=i,a+=1),!o.family&&(i=r.fontFamily)&&(o.family=i,a+=1),!o.size&&(i=r.fontSize)&&(o.size=i,a+=1)),n=n.parentNode; -return o},$t._addFormat=function(e,t,r){var i,o,a,s,d,l,c,h,f=this._root;if(r.collapsed)i=S(this.createElement(e,t),f),ut(r,i),r.setStart(i.firstChild,i.firstChild.length),r.collapse(!0);else{if(o=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,o.currentNode=a,o.filter(a)||(a=o.nextNode(),d=0),!a)return r;do c=o.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),i=this.createElement(e,t),C(c,i),i.appendChild(c));while(o.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},$t._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(rt?(i=a.createTextNode(Z),this._didAddZWS()):i=a.createTextNode(""),ut(n,i));for(var s=n.commonAncestorContainer;o(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,i,o=e.nodeType===I;if(!vt(n,e,!0))return void("INPUT"===e.nodeName||o&&!e.data||u.push([t,e]));if(o)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=i)i=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,_(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return E(s,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},$t.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),ot||this._docWasChanged(),this):this};var nn={DT:"DD",DD:"DT",LI:"LI"},rn=function(e,t,n,r){var i=nn[t.nodeName],o=null,a=T(n,r,t.parentNode,e._root),s=e._config;return i||(i=s.blockTag,o=s.blockAttributes),f(a,i,o)||(t=N(a.ownerDocument,i,o),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(_(a)),a=t),a};$t.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,i=Nt(n,r),o=St(n,r);if(i&&o)do if(e(i)||i===o)break;while(i=c(i,r));return t&&(this.setSelection(n),this._updatePath(n,!0),ot||this._docWasChanged()),this},$t.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 bt(t,r),_t(t,r),n=pt(t,r,r),ut(t,e.call(this,n)),t.endOffsett;t+=1){for(i=d[t],o=_(i),a=o.childNodes,r=a.length;r--;)s=a[r],C(s,_(s));y(o,this._root),C(i,o)}return e},fn=function(e){var t,n,r,i,o,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)||(i=r.parentNode.nodeName,o=r.previousSibling,o&&(o=o.lastChild)&&o.nodeName===i||(a=l[i.toLowerCase()],C(r,this.createElement("LI",c,[o=this.createElement(i,a)]))),o.appendChild(r));return e},un=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,i=n.parentNode,o=i.parentNode,a=n.firstChild,d=a;for(n.previousSibling&&(i=T(i,n,o,t));d&&(r=d.nextSibling,!s(d));)o.insertBefore(d,i),d=r;for("LI"===o.nodeName&&a.previousSibling&&T(o,a,o.parentNode,t);n!==e&&!n.childNodes.length;)i=n.parentNode,i.removeChild(n),n=i},this),y(e,t),e};$t._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},$t.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},$t._getHTML=function(){return this._root.innerHTML},$t._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do S(n,t);while(n=c(n,t));this._ignoreChange=!0},$t.getHTML=function(e){var t,n,r,i,o,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(i=this._getHTML().replace(/\u200B/g,""),nt)for(o=s.length;o--;)v(s[o]);return a&&this._getRangeAndRemoveBookmark(a),i},$t.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),i=this._root;r.innerHTML=e,n.appendChild(_(r)),Ht(n),Kt(n,i),y(n,i);for(var o=n;o=c(o,i);)S(o,i);for(this._ignoreChange=!0;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(i,i),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var a=this._getRangeAndRemoveBookmark()||this._createRange(i.firstChild,0);return this.saveUndoState(a),this._lastSelection=a,A.call(this),this._updatePath(a,!0),this},$t.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),o(e))ut(t,e),t.setStartAfter(e);else{for(var n,r,i=this._root,a=Nt(t,i)||i;a!==i&&!a.nextSibling;)a=a.parentNode;a!==i&&(n=a.parentNode,r=T(n,a.nextSibling,i,i)),r?i.insertBefore(e,r):(i.appendChild(e),r=this.createDefaultBlock(),i.appendChild(r)),t.setStart(r,0),t.setEnd(r,0),Ct(t)}return this.focus(),this.setSelection(t),this._updatePath(t),ot||this._docWasChanged(),this},$t.insertImage=function(e,t){var n=this.createElement("IMG",k({src:e},t));return this.insertElement(n),n};var pn=/\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,gn=function(e,t,r){for(var i,o,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;i=f.nextNode();)for(o=i.data,a=i.parentNode;s=pn.exec(o);)d=s.index,l=d+s[0].length,d&&(c=h.createTextNode(o.slice(0,d)),a.insertBefore(c,i)),c=r.createElement("A",k({href:s[1]?/^(?:ht|f)tps?:/.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[2]},p)),c.textContent=o.slice(d,l),a.insertBefore(c,i),i.data=o=o.slice(l)};$t.insertHTML=function(e,t){var n,r,i,o,a,s,d,l=this.getSelection(),h=this._doc;"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?(o=DOMPurify.sanitize(e,{WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}),o=h.importNode(o,!0)):(t&&(n=e.indexOf(""),r=e.lastIndexOf(""),n>-1&&r>-1&&(e=e.slice(n+20,r))),i=this.createElement("DIV"),i.innerHTML=e,o=h.createDocumentFragment(),o.appendChild(_(i))),this.saveUndoState(l);try{for(a=this._root,s=o,d={fragment:o,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},gn(o,o,this),Ht(o),Kt(o,null),Wt(o),o.normalize();s=c(s,o);)S(s,null);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(mt(l,d.fragment,a),ot||this._docWasChanged(),l.collapse(!1),this._ensureBottomLine()),this.setSelection(l),this._updatePath(l,!0)}catch(f){this.didError(f)}return this};var mn=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};$t.insertPlainText=function(e,t){var n,r,i,o,a=e.split("\n"),s=this._config,d=s.blockTag,l=s.blockAttributes,c="",h="<"+d;for(n in l)h+=" "+n+'="'+mn(l[n])+'"';for(h+=">",r=0,i=a.length;i>r;r+=1)o=a[r],o=mn(o).replace(/ (?= )/g," "),r&&i>r+1&&(o=h+(o||"
")+c),a[r]=o;return this.insertHTML(a.join(""),t)};var vn=function(e,t,n){return function(){return this[e](t,n),this.focus()}};$t.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},$t.bold=vn("changeFormat",{tag:"B"}),$t.italic=vn("changeFormat",{tag:"I"}),$t.underline=vn("changeFormat",{tag:"U"}),$t.strikethrough=vn("changeFormat",{tag:"S"}),$t.subscript=vn("changeFormat",{tag:"SUB"},{tag:"SUP"}),$t.superscript=vn("changeFormat",{tag:"SUP"},{tag:"SUB"}),$t.removeBold=vn("changeFormat",null,{tag:"B"}),$t.removeItalic=vn("changeFormat",null,{tag:"I"}),$t.removeUnderline=vn("changeFormat",null,{tag:"U"}),$t.removeStrikethrough=vn("changeFormat",null,{tag:"S"}),$t.removeSubscript=vn("changeFormat",null,{tag:"SUB"}),$t.removeSuperscript=vn("changeFormat",null,{tag:"SUP"}),$t.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={}),k(t,this._config.tagAttributes.a),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},$t.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},$t.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},$t.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},$t.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}}:null,{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},$t.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},$t.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()},$t.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},$t.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||(bt(e,t),n=t),n.nodeType===I)return this;this.saveUndoState(e),_t(e,n);for(var r,i,o,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,o=n.childNodes,g?(n.insertBefore(u,p),l=st.call(o,g),h=st.call(o,r)+1):(l=st.call(o,p),h=l),i={startContainer:n,startOffset:l,endContainer:n,endOffset:h},E(n,i),e.setStart(i.startContainer,i.startOffset),e.setEnd(i.endContainer,i.endOffset),Ct(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},$t.increaseQuoteLevel=vn("modifyBlocks",on),$t.decreaseQuoteLevel=vn("modifyBlocks",an),$t.makeUnorderedList=vn("modifyBlocks",ln),$t.makeOrderedList=vn("modifyBlocks",cn),$t.removeList=vn("modifyBlocks",hn),$t.increaseListLevel=vn("modifyBlocks",fn),$t.decreaseListLevel=vn("modifyBlocks",un),"object"==typeof exports?module.exports=L:"function"==typeof define&&define.amd?define(function(){return L}):(G.Squire=L,top!==G&&"true"===e.documentElement.getAttribute("data-squireinit")&&(G.editor=new L(e),G.onEditorLoad&&(G.onEditorLoad(G.editor),G.onEditorLoad=null)))}(document); \ No newline at end of file +!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&&!!pe[e.nodeName]}function i(e){return ue.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+"]"),o&&(he.call(o,Z)>-1&&(a+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),he.call(o,G)>-1&&(a+="[color="+e.style.color.replace(/ /g,"")+"]"),he.call(o,j)>-1&&(a+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),he.call(o,Q)>-1&&(a+="[fontSize="+e.style.fontSize+"]")))),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 _(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function N(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 S(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=O(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;se&&r&&r.nodeType===I&&!r.data;)e.removeChild(r),r=e.firstChild;r||(se?(n=a.createTextNode(V),O(a)._didAddZWS()):n=a.createTextNode(""))}else if(ae){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=N(a,"BR");(r=e.lastElementChild)&&!i(r);)e=r;if(n)try{e.appendChild(n)}catch(d){O(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=O(l)._config;for(n=0,r=d.length;r>n;n+=1)o=d[n],a="BR"===o.nodeName,!a&&i(o)?(c||(c=N(l,h.blockTag,h.blockAttributes)),c.appendChild(o),n-=1,r-=1):(a||c)&&(c||(c=N(l,h.blockTag,h.blockAttributes)),S(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(S(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));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(_(t)),b(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),ne&&(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=N(a,"DIV"),r.appendChild(_(o)),o.appendChild(r)}v(e),n=!s(e),o.appendChild(_(e)),n&&y(o,t),i&&x(i,t)}else d&&(o=N(a,"DIV"),e.insertBefore(o,i),S(o,t))}function O(e){for(var t,n=Je.length;n--;)if(t=Je[n],t._doc===e)return t;return null}function k(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?k(e[n],r):r;return e}function L(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._isFocused=!1,this._lastSelection=null,de&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"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,le?(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",A),this.addEventListener("mousedown",B),this.addEventListener("touchstart",B),this.addEventListener("focus",D),this._awaitingPaste=!1,this.addEventListener(te?"beforecut":"cut",Ve),this.addEventListener("copy",$e),this.addEventListener(te?"beforepaste":"paste",Ye),this.addEventListener("drop",Xe),this.addEventListener(ne?"keypress":"keydown",Be),this._keyHandlers=Object.create(Pe),this.setConfig(t),te&&(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){}Je.push(this),this.setHTML("")}function A(){this._restoreSelection=!0}function B(){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,z=0,W=1,q=2,K=3,Z="highlight",G="colour",j="font",Q="size",V="​",$=e.defaultView,Y=navigator.userAgent,X=/iP(?:ad|hone|od)/.test(Y),J=/Mac OS X/.test(Y),ee=/Gecko\//.test(Y),te=/Trident\/[456]\./.test(Y),ne=!!$.opera,re=/Edge\//.test(Y),oe=!re&&/WebKit\//.test(Y),ie=J?"meta-":"ctrl-",ae=te||ne,se=te||oe,de=te,le="undefined"!=typeof MutationObserver,ce=/[^ \t\r\n]/,he=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var fe={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(fe[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(fe[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(fe[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var ue=/^(?:#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)$/,pe={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},ge=function(e,t){for(var n=e.childNodes;t&&e.nodeType===P;)e=n[t-1],n=e.childNodes,t=n.length;return e},me=function(e,t){if(e.nodeType===P){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(W,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(z,r)<1,s=e.compareBoundaryPoints(q,r)>-1;return a&&s},ye=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))},Te=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=he.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=he.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},be=function(e,t){var n,r=e.startContainer;return i(r)?n=l(r,t):a(r)?n=r:(n=ge(r,e.startOffset),n=c(n,t)),n&&Se(e,n,!0)?n:null},Ee=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=me(o,e.endOffset),!n||!p(t,n))for(n=t;r=n.lastChild;)n=r;n=l(n,t)}return n&&Se(e,n,!0)?n:null},xe=new n(null,H|M,function(e){return e.nodeType===I?ce.test(e.data):"IMG"===e.nodeName}),Oe=function(e,t){var n,r=e.startContainer,o=e.startOffset;if(xe.root=null,r.nodeType===I){if(o)return!1;n=r}else if(n=me(r,o),n&&!p(t,n)&&(n=null),!n&&(n=ge(r,o),n.nodeType===I&&n.length))return!1;return xe.currentNode=n,xe.root=be(e,t),!xe.previousNode()},ke=function(e,t){var n,r=e.endContainer,o=e.endOffset;if(xe.root=null,r.nodeType===I){if(n=r.data.length,n&&n>o)return!1;xe.currentNode=r}else xe.currentNode=ge(r,o);return xe.root=Ee(e,t),!xe.nextNode()},Le=function(e,t){var n,r=be(e,t),o=Ee(e,t);r&&o&&(n=r.parentNode,e.setStart(n,he.call(n.childNodes,r)),n=o.parentNode,e.setEnd(n,he.call(n.childNodes,o)+1))},Ae={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},Be=function(e){var t=e.keyCode,n=Ae[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),ne&&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),_e(o,this._root),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},De=function(e){return function(t,n){n.preventDefault(),t[e]()}},Re=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)}},Ue=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===V);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,he.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),a(n)||(n=l(n,e._root)),S(n,e._root),ye(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)}},Pe={enter:function(e,t,n){var r,o,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),Ct(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||_e(n,a),r=be(n,a),!r||/^T[HD]$/.test(r.nodeName))return ve(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(mt,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(ct,n)}for(i=st(e,r,n.startContainer,n.startOffset),rt(r),Ze(r),S(r,a);i.nodeType===P;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===V)){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&&!ne)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(Oe(n,r)){t.preventDefault();var o,i=be(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(mt,n);if(u(i,r,"BLOCKQUOTE"))return e.modifyBlocks(lt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Ue(e)},0);else t.preventDefault(),_e(n,r),Ue(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(ke(n,l)){if(t.preventDefault(),r=be(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(),Te(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),ye(n),void Ue(e,n);e.setSelection(i),setTimeout(function(){Ue(e)},0)}else t.preventDefault(),_e(n,l),Ue(e,n)},tab:function(e,t,n){var r,o,i=e._root;if(e._removeZWS(),n.collapsed&&Oe(n,i))for(r=be(n,i);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(gt,n));break}r=o}},"shift-tab":function(e,t,n){var r,o=e._root;e._removeZWS(),n.collapsed&&Oe(n,o)&&(r=n.startContainer,(u(r,o,"UL")||u(r,o,"OL"))&&(t.preventDefault(),e.modifyBlocks(mt,n)))},space:function(e,t,n){var r,o;e._recordUndoState(n),Ct(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()}};J&&ee&&(Pe["meta-left"]=function(e,t){t.preventDefault();var n=nt(e);n&&n.modify&&n.modify("move","backward","lineboundary")},Pe["meta-right"]=function(e,t){t.preventDefault();var n=nt(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),J||(Pe.pageup=function(e){e.moveCursorToStart()},Pe.pagedown=function(e){e.moveCursorToEnd()}),Pe[ie+"b"]=Re("B"),Pe[ie+"i"]=Re("I"),Pe[ie+"u"]=Re("U"),Pe[ie+"shift-7"]=Re("S"),Pe[ie+"shift-5"]=Re("SUB",{tag:"SUP"}),Pe[ie+"shift-6"]=Re("SUP",{tag:"SUB"}),Pe[ie+"shift-8"]=De("makeUnorderedList"),Pe[ie+"shift-9"]=De("makeOrderedList"),Pe[ie+"["]=De("decreaseQuoteLevel"),Pe[ie+"]"]=De("increaseQuoteLevel"),Pe[ie+"y"]=De("redo"),Pe[ie+"z"]=De("undo"),Pe[ie+"shift-z"]=De("redo");var Ie={1:10,2:13,3:16,4:18,5:24,6:32,7:48},we={backgroundColor:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":Z,style:"background-color:"+t})}},color:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":G,style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return N(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return N(e,"I")}},fontFamily:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":j,style:"font-family:"+t})}},fontSize:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":Q,style:"font-size:"+t})}},textDecoration:{regexp:/^underline/i,replace:function(e){return N(e,"U")}}},Fe=function(e){return function(t,n){var r=N(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(_(t)),r}},Me=function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in we)r=we[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),a||(a=s),i&&i.appendChild(s),i=s,e.style[n]="");return a&&(i.appendChild(_(e)),"SPAN"===e.nodeName?t.replaceChild(a,e):e.appendChild(a)),i||e},He={P:Me,SPAN:Me,STRONG:Fe("B"),EM:Fe("I"),INS:Fe("U"),STRIKE:Fe("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=N(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=N(c,"SPAN",{"class":"size",style:"font-size:"+Ie[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=N(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=N(c,"SPAN")),t.replaceChild(a,e),i.appendChild(_(e)),i},TT:function(e,t){var n=N(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(_(e)),n}},ze=/^(?: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)$/,We=/^(?:HEAD|META|STYLE)/,qe=new n(null,H|M,function(){return!0}),Ke=function St(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(qe.root=n,r=0,o=g.length;o>r;r+=1)if(a=g[r],s=a.nodeName,d=a.nodeType,l=He[s],d===P){if(c=a.childNodes.length,l)a=l(a,e);else{if(We.test(s)){e.removeChild(a),r-=1,o-=1;continue}if(!ze.test(s)&&!i(a)){r-=1,o+=c-1,e.replaceChild(_(a),a);continue}}c&&St(a,t||"PRE"===s)}else{if(d===I){if(u=a.data,h=!ce.test(u.charAt(0)),f=!ce.test(u.charAt(u.length-1)),t||!h&&!f)continue;if(h){for(qe.currentNode=a;(p=qe.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(qe.currentNode=a;(p=qe.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},Ze=function yt(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):(yt(t),i(t)&&!t.firstChild&&e.removeChild(t))},Ge=function(e){return e.nodeType===P?"BR"===e.nodeName:ce.test(e.data)},je=function(e){for(var t,r=e.parentNode;i(r);)r=r.parentNode;return t=new n(r,M|H,Ge),t.currentNode=e,!!t.nextNode()},Qe=function(e,t){var n,r,o,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=je(a[n]);for(;d--;)r=a[d],o=r.parentNode,o&&(s[d]?i(o)||y(o,t):v(r))},Ve=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._root,i=this;this.saveUndoState(n),re||X||!t?setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0):(Te(n,o),r.appendChild(_e(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},$e=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");re||X||!t||(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},Ye=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,h=this;if(!re&&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,!re&&o&&(he.call(o,"text/html")>-1||!ee&&he.call(o,"text/plain")>-1&&he.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,_=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(_),u.selectNodeContents(_),this.setSelection(u),setTimeout(function(){try{h._awaitingPaste=!1;for(var e,t,n="",r=_;_=r;)r=_.nextSibling,v(_),e=_.firstChild,e&&e===_.lastChild&&"DIV"===e.nodeName&&(_=e),n+=_.innerHTML;t=h._createRange(p,g,m,C),h.setSelection(t),n&&h.insertHTML(n,!0)}catch(o){h.didError(o)}},0)},Xe=function(e){for(var t=e.dataTransfer.types,n=t.length,r=!1,o=!1;n--;)switch(t[n]){case"text/plain":r=!0;break;case"text/html":o=!0;break;default:return}(o||r)&&this.saveUndoState()},Je=[],et=L.prototype;et.setConfig=function(e){return e=k({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},undo:{documentSizeThreshold:-1,undoLimit:-1}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},et.createElement=function(e,t,n){return N(this._doc,e,t,n)},et.createDefaultBlock=function(e){var t=this._config;return S(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},et.didError=function(e){console.log(e)},et.getDocument=function(){return this._doc},et.getRoot=function(){return this._root},et.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 tt={pathChange:1,select:1,input:1,undoStateChange:1};et.fireEvent=function(e,t){var n,r,o,i=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=p(this._root,this._doc.activeElement),"focus"===e){if(!n||this._isFocused)return this;this._isFocused=!0}else{if(n||!this._isFocused)return this;this._isFocused=!1}if(i)for(t||(t={}),t.type!==e&&(t.type=e),i=i.slice(),r=i.length;r--;){o=i[r];try{o.handleEvent?o.handleEvent(t):o.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},et.destroy=function(){var e,t=Je.length,n=this._events;for(e in n)this.removeEventListener(e);for(this._mutation&&this._mutation.disconnect();t--;)Je[t]===this&&Je.splice(t,1);this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0},et.handleEvent=function(e){this.fireEvent(e.type,e)},et.addEventListener=function(e,t){var n=this._events[e],r=this._root;return t?(n||(n=this._events[e]=[],tt[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)},et.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],tt[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},et._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},et.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=V,ve(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},et._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return ye(n),this.setSelection(n),this},et.moveCursorToStart=function(){return this._moveCursorTo(!0)},et.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var nt=function(e){return e._win.getSelection()||null};et.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused){X&&this._win.focus();var t=nt(this);t&&(t.removeAllRanges(),t.addRange(e))}else A.call(this);return this},et.getSelection=function(){var e,t,n,r=nt(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},et.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,H|M,function(e){return Se(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},et.getPath=function(){return this._path};var rt=function(e){for(var t,r,o,a=new n(e,H,function(){return!0},!1);r=a.nextNode();)for(;(o=r.data.indexOf(V))>-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)}};et._didAddZWS=function(){this._hasZWS=!0},et._removeZWS=function(){this._hasZWS&&(rt(this._root),this._hasZWS=!1)},et._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")},et._updatePathOnEvent=function(){var e=this;e._willUpdatePath||(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1,e._updatePath(e.getSelection())},0))},et.focus=function(){return this._root.focus(),this},et.blur=function(){return this._root.blur(),this};var ot="squire-selection-start",it="squire-selection-end";et._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:ot,type:"hidden"}),r=this.createElement("INPUT",{id:it,type:"hidden"});ve(e,n),e.collapse(!1),ve(e,r),n.compareDocumentPosition(r)&U&&(n.id=it,r.id=ot,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},et._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+ot),r=t.querySelector("#"+it);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:he.call(i.childNodes,n),endOffset:he.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},et._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},et._docWasChanged=function(){if(!this._ignoreAllChanges){if(le&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},et._recordUndoState=function(e){if(!this._isInUndoState){var t,n=this._undoIndex+=1,r=this._undoStack,o=this._config.undo,i=o.documentSizeThreshold,a=o.undoLimit;n-1&&2*t.length>i&&a>-1&&n>a&&(r.splice(0,n-a),n=this._undoIndex=a,this._undoStackLength=a),r[n]=t,this._undoStackLength+=1,this._isInUndoState=!0}},et.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._isInUndoState||(this._recordUndoState(e),this._getRangeAndRemoveBookmark(e)),this},et.undo=function(){if(0!==this._undoIndex||!this._isInUndoState){this._recordUndoState(this.getSelection()),this._undoIndex-=1,this._setHTML(this._undoStack[this._undoIndex]);var e=this._getRangeAndRemoveBookmark();e&&this.setSelection(e),this._isInUndoState=!0,this.fireEvent("undoStateChange",{canUndo:0!==this._undoIndex,canRedo:!0}),this.fireEvent("input")}return this},et.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(t>e+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},et.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 Se(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},et.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},et._addFormat=function(e,t,r){var o,i,a,s,d,l,c,h,f=this._root;if(r.collapsed)o=S(this.createElement(e,t),f),ve(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)&&Se(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},et._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var o,a=this._doc;n.collapsed&&(se?(o=a.createTextNode(V),this._didAddZWS()):o=a.createTextNode(""),ve(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(!Se(n,e,!1)){var r,o,i=e.nodeType===I;if(!Se(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 Se(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,_(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},et.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),le||this._docWasChanged(),this):this};var at={DT:"DD",DD:"DT",LI:"LI"},st=function(e,t,n,r){var o=at[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=N(a.ownerDocument,o,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(_(a)),a=t),a};et.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,o=be(n,r),i=Ee(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),le||this._docWasChanged()),this},et.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 Le(t,r),Te(t,r),n=Ce(t,r,r),ve(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=_(o),a=i.childNodes,r=a.length;r--;)s=a[r],C(s,_(s));y(i,this._root),C(o,i)}return e},gt=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},mt=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};et._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},et.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},et._getHTML=function(){return this._root.innerHTML},et._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do S(n,t);while(n=c(n,t));this._ignoreChange=!0},et.getHTML=function(e){var t,n,r,o,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),ae)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,""),ae)for(i=s.length;i--;)v(s[i]);return a&&this._getRangeAndRemoveBookmark(a),o},et.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),o=this._root;r.innerHTML=e,n.appendChild(_(r)),Ke(n),Qe(n,o),y(n,o);for(var i=n;i=c(i,o);)S(i,o);for(this._ignoreChange=!0;t=o.lastChild;)o.removeChild(t);o.appendChild(n),S(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,A.call(this),this._updatePath(a,!0),this},et.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),i(e))ve(t,e),t.setStartAfter(e);else{for(var n,r,o=this._root,a=be(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),ye(t)}return this.focus(),this.setSelection(t),this._updatePath(t),le||this._docWasChanged(),this},et.insertImage=function(e,t){var n=this.createElement("IMG",k({src:e},t));return this.insertElement(n),n};var vt=/\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,Ct=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=vt.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",k({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)};et.insertHTML=function(e,t){var n,r,o,i,a,s,d,l=this.getSelection(),h=this._doc;"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?(i=DOMPurify.sanitize(e,{WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}),i=h.importNode(i,!0)):(t&&(n=e.indexOf(""),r=e.lastIndexOf(""),n>-1&&r>-1&&(e=e.slice(n+20,r))),o=this.createElement("DIV"),o.innerHTML=e,i=h.createDocumentFragment(),i.appendChild(_(o))),this.saveUndoState(l);try{for(a=this._root,s=i,d={fragment:i,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},Ct(i,i,this),Ke(i),Qe(i,null),Ze(i),i.normalize();s=c(s,i);)S(s,null);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Ne(l,d.fragment,a),le||this._docWasChanged(),l.collapse(!1),this._ensureBottomLine()),this.setSelection(l),this._updatePath(l,!0)}catch(f){this.didError(f)}return this};var _t=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};et.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+'="'+_t(l[n])+'"';for(h+=">",r=0,o=a.length;o>r;r+=1)i=a[r],i=_t(i).replace(/ (?= )/g," "),r&&o>r+1&&(i=h+(i||"
")+c),a[r]=i;return this.insertHTML(a.join(""),t)};var Nt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};et.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},et.bold=Nt("changeFormat",{tag:"B"}),et.italic=Nt("changeFormat",{tag:"I"}),et.underline=Nt("changeFormat",{tag:"U"}),et.strikethrough=Nt("changeFormat",{tag:"S"}),et.subscript=Nt("changeFormat",{tag:"SUB"},{tag:"SUP"}),et.superscript=Nt("changeFormat",{tag:"SUP"},{tag:"SUB"}),et.removeBold=Nt("changeFormat",null,{tag:"B"}),et.removeItalic=Nt("changeFormat",null,{tag:"I"}),et.removeUnderline=Nt("changeFormat",null,{tag:"U"}),et.removeStrikethrough=Nt("changeFormat",null,{tag:"S"}),et.removeSubscript=Nt("changeFormat",null,{tag:"SUB"}),et.removeSuperscript=Nt("changeFormat",null,{tag:"SUP"}),et.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;ve(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),k(t,this._config.tagAttributes.a),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},et.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},et.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},et.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},et.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}}:null,{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},et.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},et.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()},et.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},et.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||(Le(e,t),n=t),n.nodeType===I)return this;this.saveUndoState(e),Te(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=he.call(i,g),h=he.call(i,r)+1):(l=he.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),ye(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},et.increaseQuoteLevel=Nt("modifyBlocks",dt),et.decreaseQuoteLevel=Nt("modifyBlocks",lt),et.makeUnorderedList=Nt("modifyBlocks",ft),et.makeOrderedList=Nt("modifyBlocks",ut),et.removeList=Nt("modifyBlocks",pt),et.increaseListLevel=Nt("modifyBlocks",gt),et.decreaseListLevel=Nt("modifyBlocks",mt),"object"==typeof exports?module.exports=L:"function"==typeof define&&define.amd?define(function(){return L}):($.Squire=L,top!==$&&"true"===e.documentElement.getAttribute("data-squireinit")&&($.editor=new L(e),$.onEditorLoad&&($.onEditorLoad($.editor),$.onEditorLoad=null)))}(document); \ No newline at end of file diff --git a/source/Clean.js b/source/Clean.js index 49964c6..fd67969 100644 --- a/source/Clean.js +++ b/source/Clean.js @@ -15,7 +15,7 @@ var styleToSemantic = { regexp: notWS, replace: function ( doc, colour ) { return createElement( doc, 'SPAN', { - 'class': 'highlight', + 'class': HIGHLIGHT_CLASS, style: 'background-color:' + colour }); } @@ -24,7 +24,7 @@ var styleToSemantic = { regexp: notWS, replace: function ( doc, colour ) { return createElement( doc, 'SPAN', { - 'class': 'colour', + 'class': COLOUR_CLASS, style: 'color:' + colour }); } @@ -45,7 +45,7 @@ var styleToSemantic = { regexp: notWS, replace: function ( doc, family ) { return createElement( doc, 'SPAN', { - 'class': 'font', + 'class': FONT_FAMILY_CLASS, style: 'font-family:' + family }); } @@ -54,7 +54,7 @@ var styleToSemantic = { regexp: notWS, replace: function ( doc, size ) { return createElement( doc, 'SPAN', { - 'class': 'size', + 'class': FONT_SIZE_CLASS, style: 'font-size:' + size }); } diff --git a/source/Constants.js b/source/Constants.js index a2f30d0..e72039e 100644 --- a/source/Constants.js +++ b/source/Constants.js @@ -13,6 +13,11 @@ var START_TO_END = 1; // Range.START_TO_END var END_TO_END = 2; // Range.END_TO_END var END_TO_START = 3; // Range.END_TO_START +var HIGHLIGHT_CLASS = 'highlight'; +var COLOUR_CLASS = 'colour'; +var FONT_FAMILY_CLASS = 'font'; +var FONT_SIZE_CLASS = 'size'; + var ZWS = '\u200B'; var win = doc.defaultView; diff --git a/source/Node.js b/source/Node.js index 7bfb77c..bb6b09b 100644 --- a/source/Node.js +++ b/source/Node.js @@ -113,6 +113,20 @@ function getPath ( node, root ) { if ( dir = node.dir ) { path += '[dir=' + dir + ']'; } + if( classNames ) { + if ( indexOf.call( classNames, HIGHLIGHT_CLASS ) > -1 ) { + path += '[backgroundColor=' + node.style.backgroundColor.replace(/ /g,'') + ']'; + } + if ( indexOf.call( classNames, COLOUR_CLASS ) > -1 ) { + path += '[color=' + node.style.color.replace(/ /g,'') + ']'; + } + if ( indexOf.call( classNames, FONT_FAMILY_CLASS ) > -1 ) { + path += '[fontFamily=' + node.style.fontFamily.replace(/ /g,'') + ']'; + } + if ( indexOf.call( classNames, FONT_SIZE_CLASS ) > -1 ) { + path += '[fontSize=' + node.style.fontSize + ']'; + } + } } } return path; From 9b75e26451fa0015b6ce04fb6f81a32dab1903ca Mon Sep 17 00:00:00 2001 From: Andy Kauffman Date: Thu, 7 Jul 2016 09:38:06 -0400 Subject: [PATCH 2/6] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 047e635..e8c0b75 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ Returns self (the Squire instance). ### getPath -Returns the path through the DOM tree from the `` element to the current current cursor position. This is a string consisting of the tag, id and class names in CSS format. For example `BODY>BLOCKQUOTE>DIV#id>STRONG>SPAN.font>EM`. If a selection has been made, so different parts of the selection may have different paths, the value will be `(selection)`. The path is useful for efficiently determining the current formatting for bold, italic, underline etc, and thus determining button state. If a selection has been made, you can has the `hasFormat` method instead to get the current state for the properties you care about. +Returns the path through the DOM tree from the `` element to the current current cursor position. This is a string consisting of the tag, id, class, font, and color names in CSS format. For example `BODY>BLOCKQUOTE>DIV#id>STRONG>SPAN.font[fontFamily=Arial,sans-serif]>EM`. If a selection has been made, so different parts of the selection may have different paths, the value will be `(selection)`. The path is useful for efficiently determining the current formatting for bold, italic, underline etc, and thus determining button state. If a selection has been made, you can has the `hasFormat` method instead to get the current state for the properties you care about. ### getFontInfo From 1c9dc9ebb505612475627c3caec8a11769dbb00d Mon Sep 17 00:00:00 2001 From: Andy Kauffman Date: Thu, 7 Jul 2016 09:39:06 -0400 Subject: [PATCH 3/6] Update getPath tests --- test/squire.spec.js | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/test/squire.spec.js b/test/squire.spec.js index 52cf70f..6705f61 100644 --- a/test/squire.spec.js +++ b/test/squire.spec.js @@ -195,6 +195,76 @@ describe('Squire RTE', function () { }); }); + describe('getPath', function () { + var startHTML; + beforeEach( function () { + startHTML = '
one two three four five
'; + editor.setHTML(startHTML); + + var range = doc.createRange(); + range.setStart(doc.body.childNodes.item(0), 0); + range.setEnd(doc.body.childNodes.item(0), 1); + editor.setSelection(range); + }); + + it('returns the path to the selection', function () { + editor.insertHTML('Bold Text'); + expect(editor.getPath(), 'to be', 'DIV>B'); + }); + + it('includes id in the path', function () { + editor.insertHTML('
Text
'); + expect(editor.getPath(), 'to be', 'DIV#spanId'); + }); + + it('includes class name in the path', function () { + editor.insertHTML('
Text
'); + expect(editor.getPath(), 'to be', 'DIV.myClass'); + }); + + it('includes all class names in the path', function () { + editor.insertHTML('
Text
'); + expect(editor.getPath(), 'to be', 'DIV.myClass.myClass2.myClass3'); + }); + + it('includes direction in the path', function () { + editor.insertHTML('
Text
'); + expect(editor.getPath(), 'to be', 'DIV[dir=rtl]'); + }); + + it('includes highlight value in the path', function () { + editor.insertHTML('
Text
'); + expect(editor.getPath(), 'to be', 'DIV.highlight[backgroundColor=rgb(255,0,0)]'); + }); + + it('includes color value in the path', function () { + editor.insertHTML('
Text
'); + expect(editor.getPath(), 'to be', 'DIV.colour[color=rgb(255,0,0)]'); + }); + + it('includes font family value in the path', function () { + editor.insertHTML('
Text
'); + expect(editor.getPath(), 'to be', 'DIV.font[fontFamily=Arial,sans-serif]'); + }); + + it('includes font size value in the path', function () { + editor.insertHTML('
Text
'); + expect(editor.getPath(), 'to be', 'DIV.size[fontSize=12pt]'); + }); + + it('is (selection) when the selection is a range', function() { + var range = doc.createRange(); + range.setStart(doc.body.childNodes.item(0).childNodes.item(0), 0); + range.setEnd(doc.body.childNodes.item(0).childNodes.item(3), 0); + editor.setSelection(range); + + //Manually tell it to update the path + editor._updatePath(range); + + expect(editor.getPath(), 'to be', '(selection)'); + }); + }); + afterEach(function () { editor = null; var iframe = document.getElementById('testFrame'); From f5a816be76d8b1802c6e8f21e251b98c55e90637 Mon Sep 17 00:00:00 2001 From: Andy Kauffman Date: Thu, 7 Jul 2016 10:20:49 -0400 Subject: [PATCH 4/6] Update failing test after merge --- test/squire.spec.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/squire.spec.js b/test/squire.spec.js index 6705f61..2d9869a 100644 --- a/test/squire.spec.js +++ b/test/squire.spec.js @@ -208,7 +208,13 @@ describe('Squire RTE', function () { }); it('returns the path to the selection', function () { - editor.insertHTML('Bold Text'); + var range = doc.createRange(); + range.setStart(doc.body.childNodes.item(0).childNodes.item(1), 0); + range.setEnd(doc.body.childNodes.item(0).childNodes.item(1), 0); + editor.setSelection(range); + + //Manually tell it to update the path + editor._updatePath(range); expect(editor.getPath(), 'to be', 'DIV>B'); }); From 00c1363d1714996bbb15b02f82a78222b9aeb51a Mon Sep 17 00:00:00 2001 From: Andy Kauffman Date: Fri, 8 Jul 2016 08:59:01 -0400 Subject: [PATCH 5/6] Remove strange empty line in build/squire.js --- build/squire.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/squire.js b/build/squire.js index 12bef72..058dd83 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1,3 +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&&!!pe[e.nodeName]}function i(e){return ue.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+"]"),o&&(he.call(o,Z)>-1&&(a+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),he.call(o,G)>-1&&(a+="[color="+e.style.color.replace(/ /g,"")+"]"),he.call(o,j)>-1&&(a+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),he.call(o,Q)>-1&&(a+="[fontSize="+e.style.fontSize+"]")))),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 _(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function N(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 S(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=O(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;se&&r&&r.nodeType===I&&!r.data;)e.removeChild(r),r=e.firstChild;r||(se?(n=a.createTextNode(V),O(a)._didAddZWS()):n=a.createTextNode(""))}else if(ae){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=N(a,"BR");(r=e.lastElementChild)&&!i(r);)e=r;if(n)try{e.appendChild(n)}catch(d){O(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=O(l)._config;for(n=0,r=d.length;r>n;n+=1)o=d[n],a="BR"===o.nodeName,!a&&i(o)?(c||(c=N(l,h.blockTag,h.blockAttributes)),c.appendChild(o),n-=1,r-=1):(a||c)&&(c||(c=N(l,h.blockTag,h.blockAttributes)),S(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(S(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));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(_(t)),b(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),ne&&(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=N(a,"DIV"),r.appendChild(_(o)),o.appendChild(r)}v(e),n=!s(e),o.appendChild(_(e)),n&&y(o,t),i&&x(i,t)}else d&&(o=N(a,"DIV"),e.insertBefore(o,i),S(o,t))}function O(e){for(var t,n=Je.length;n--;)if(t=Je[n],t._doc===e)return t;return null}function k(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?k(e[n],r):r;return e}function L(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._isFocused=!1,this._lastSelection=null,de&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"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,le?(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",A),this.addEventListener("mousedown",B),this.addEventListener("touchstart",B),this.addEventListener("focus",D),this._awaitingPaste=!1,this.addEventListener(te?"beforecut":"cut",Ve),this.addEventListener("copy",$e),this.addEventListener(te?"beforepaste":"paste",Ye),this.addEventListener("drop",Xe),this.addEventListener(ne?"keypress":"keydown",Be),this._keyHandlers=Object.create(Pe),this.setConfig(t),te&&(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){}Je.push(this),this.setHTML("")}function A(){this._restoreSelection=!0}function B(){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,z=0,W=1,q=2,K=3,Z="highlight",G="colour",j="font",Q="size",V="​",$=e.defaultView,Y=navigator.userAgent,X=/iP(?:ad|hone|od)/.test(Y),J=/Mac OS X/.test(Y),ee=/Gecko\//.test(Y),te=/Trident\/[456]\./.test(Y),ne=!!$.opera,re=/Edge\//.test(Y),oe=!re&&/WebKit\//.test(Y),ie=J?"meta-":"ctrl-",ae=te||ne,se=te||oe,de=te,le="undefined"!=typeof MutationObserver,ce=/[^ \t\r\n]/,he=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var fe={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(fe[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(fe[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(fe[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var ue=/^(?:#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)$/,pe={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},ge=function(e,t){for(var n=e.childNodes;t&&e.nodeType===P;)e=n[t-1],n=e.childNodes,t=n.length;return e},me=function(e,t){if(e.nodeType===P){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(W,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(z,r)<1,s=e.compareBoundaryPoints(q,r)>-1;return a&&s},ye=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))},Te=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=he.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=he.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},be=function(e,t){var n,r=e.startContainer;return i(r)?n=l(r,t):a(r)?n=r:(n=ge(r,e.startOffset),n=c(n,t)),n&&Se(e,n,!0)?n:null},Ee=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=me(o,e.endOffset),!n||!p(t,n))for(n=t;r=n.lastChild;)n=r;n=l(n,t)}return n&&Se(e,n,!0)?n:null},xe=new n(null,H|M,function(e){return e.nodeType===I?ce.test(e.data):"IMG"===e.nodeName}),Oe=function(e,t){var n,r=e.startContainer,o=e.startOffset;if(xe.root=null,r.nodeType===I){if(o)return!1;n=r}else if(n=me(r,o),n&&!p(t,n)&&(n=null),!n&&(n=ge(r,o),n.nodeType===I&&n.length))return!1;return xe.currentNode=n,xe.root=be(e,t),!xe.previousNode()},ke=function(e,t){var n,r=e.endContainer,o=e.endOffset;if(xe.root=null,r.nodeType===I){if(n=r.data.length,n&&n>o)return!1;xe.currentNode=r}else xe.currentNode=ge(r,o);return xe.root=Ee(e,t),!xe.nextNode()},Le=function(e,t){var n,r=be(e,t),o=Ee(e,t);r&&o&&(n=r.parentNode,e.setStart(n,he.call(n.childNodes,r)),n=o.parentNode,e.setEnd(n,he.call(n.childNodes,o)+1))},Ae={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},Be=function(e){var t=e.keyCode,n=Ae[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),ne&&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),_e(o,this._root),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},De=function(e){return function(t,n){n.preventDefault(),t[e]()}},Re=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)}},Ue=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===V);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,he.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),a(n)||(n=l(n,e._root)),S(n,e._root),ye(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)}},Pe={enter:function(e,t,n){var r,o,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),Ct(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||_e(n,a),r=be(n,a),!r||/^T[HD]$/.test(r.nodeName))return ve(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(mt,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(ct,n)}for(i=st(e,r,n.startContainer,n.startOffset),rt(r),Ze(r),S(r,a);i.nodeType===P;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===V)){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&&!ne)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(Oe(n,r)){t.preventDefault();var o,i=be(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(mt,n);if(u(i,r,"BLOCKQUOTE"))return e.modifyBlocks(lt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Ue(e)},0);else t.preventDefault(),_e(n,r),Ue(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(ke(n,l)){if(t.preventDefault(),r=be(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(),Te(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),ye(n),void Ue(e,n);e.setSelection(i),setTimeout(function(){Ue(e)},0)}else t.preventDefault(),_e(n,l),Ue(e,n)},tab:function(e,t,n){var r,o,i=e._root;if(e._removeZWS(),n.collapsed&&Oe(n,i))for(r=be(n,i);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(gt,n));break}r=o}},"shift-tab":function(e,t,n){var r,o=e._root;e._removeZWS(),n.collapsed&&Oe(n,o)&&(r=n.startContainer,(u(r,o,"UL")||u(r,o,"OL"))&&(t.preventDefault(),e.modifyBlocks(mt,n)))},space:function(e,t,n){var r,o;e._recordUndoState(n),Ct(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()}};J&&ee&&(Pe["meta-left"]=function(e,t){t.preventDefault();var n=nt(e);n&&n.modify&&n.modify("move","backward","lineboundary")},Pe["meta-right"]=function(e,t){t.preventDefault();var n=nt(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),J||(Pe.pageup=function(e){e.moveCursorToStart()},Pe.pagedown=function(e){e.moveCursorToEnd()}),Pe[ie+"b"]=Re("B"),Pe[ie+"i"]=Re("I"),Pe[ie+"u"]=Re("U"),Pe[ie+"shift-7"]=Re("S"),Pe[ie+"shift-5"]=Re("SUB",{tag:"SUP"}),Pe[ie+"shift-6"]=Re("SUP",{tag:"SUB"}),Pe[ie+"shift-8"]=De("makeUnorderedList"),Pe[ie+"shift-9"]=De("makeOrderedList"),Pe[ie+"["]=De("decreaseQuoteLevel"),Pe[ie+"]"]=De("increaseQuoteLevel"),Pe[ie+"y"]=De("redo"),Pe[ie+"z"]=De("undo"),Pe[ie+"shift-z"]=De("redo");var Ie={1:10,2:13,3:16,4:18,5:24,6:32,7:48},we={backgroundColor:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":Z,style:"background-color:"+t})}},color:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":G,style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return N(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return N(e,"I")}},fontFamily:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":j,style:"font-family:"+t})}},fontSize:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":Q,style:"font-size:"+t})}},textDecoration:{regexp:/^underline/i,replace:function(e){return N(e,"U")}}},Fe=function(e){return function(t,n){var r=N(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(_(t)),r}},Me=function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in we)r=we[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),a||(a=s),i&&i.appendChild(s),i=s,e.style[n]="");return a&&(i.appendChild(_(e)),"SPAN"===e.nodeName?t.replaceChild(a,e):e.appendChild(a)),i||e},He={P:Me,SPAN:Me,STRONG:Fe("B"),EM:Fe("I"),INS:Fe("U"),STRIKE:Fe("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=N(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=N(c,"SPAN",{"class":"size",style:"font-size:"+Ie[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=N(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=N(c,"SPAN")),t.replaceChild(a,e),i.appendChild(_(e)),i},TT:function(e,t){var n=N(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(_(e)),n}},ze=/^(?: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)$/,We=/^(?:HEAD|META|STYLE)/,qe=new n(null,H|M,function(){return!0}),Ke=function St(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(qe.root=n,r=0,o=g.length;o>r;r+=1)if(a=g[r],s=a.nodeName,d=a.nodeType,l=He[s],d===P){if(c=a.childNodes.length,l)a=l(a,e);else{if(We.test(s)){e.removeChild(a),r-=1,o-=1;continue}if(!ze.test(s)&&!i(a)){r-=1,o+=c-1,e.replaceChild(_(a),a);continue}}c&&St(a,t||"PRE"===s)}else{if(d===I){if(u=a.data,h=!ce.test(u.charAt(0)),f=!ce.test(u.charAt(u.length-1)),t||!h&&!f)continue;if(h){for(qe.currentNode=a;(p=qe.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(qe.currentNode=a;(p=qe.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},Ze=function yt(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):(yt(t),i(t)&&!t.firstChild&&e.removeChild(t))},Ge=function(e){return e.nodeType===P?"BR"===e.nodeName:ce.test(e.data)},je=function(e){for(var t,r=e.parentNode;i(r);)r=r.parentNode;return t=new n(r,M|H,Ge),t.currentNode=e,!!t.nextNode()},Qe=function(e,t){var n,r,o,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=je(a[n]);for(;d--;)r=a[d],o=r.parentNode,o&&(s[d]?i(o)||y(o,t):v(r))},Ve=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._root,i=this;this.saveUndoState(n),re||X||!t?setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0):(Te(n,o),r.appendChild(_e(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},$e=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");re||X||!t||(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},Ye=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,h=this;if(!re&&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,!re&&o&&(he.call(o,"text/html")>-1||!ee&&he.call(o,"text/plain")>-1&&he.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,_=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(_),u.selectNodeContents(_),this.setSelection(u),setTimeout(function(){try{h._awaitingPaste=!1;for(var e,t,n="",r=_;_=r;)r=_.nextSibling,v(_),e=_.firstChild,e&&e===_.lastChild&&"DIV"===e.nodeName&&(_=e),n+=_.innerHTML;t=h._createRange(p,g,m,C),h.setSelection(t),n&&h.insertHTML(n,!0)}catch(o){h.didError(o)}},0)},Xe=function(e){for(var t=e.dataTransfer.types,n=t.length,r=!1,o=!1;n--;)switch(t[n]){case"text/plain":r=!0;break;case"text/html":o=!0;break;default:return}(o||r)&&this.saveUndoState()},Je=[],et=L.prototype;et.setConfig=function(e){return e=k({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},undo:{documentSizeThreshold:-1,undoLimit:-1}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},et.createElement=function(e,t,n){return N(this._doc,e,t,n)},et.createDefaultBlock=function(e){var t=this._config;return S(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},et.didError=function(e){console.log(e)},et.getDocument=function(){return this._doc},et.getRoot=function(){return this._root},et.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 tt={pathChange:1,select:1,input:1,undoStateChange:1};et.fireEvent=function(e,t){var n,r,o,i=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=p(this._root,this._doc.activeElement),"focus"===e){if(!n||this._isFocused)return this;this._isFocused=!0}else{if(n||!this._isFocused)return this;this._isFocused=!1}if(i)for(t||(t={}),t.type!==e&&(t.type=e),i=i.slice(),r=i.length;r--;){o=i[r];try{o.handleEvent?o.handleEvent(t):o.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},et.destroy=function(){var e,t=Je.length,n=this._events;for(e in n)this.removeEventListener(e);for(this._mutation&&this._mutation.disconnect();t--;)Je[t]===this&&Je.splice(t,1);this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0},et.handleEvent=function(e){this.fireEvent(e.type,e)},et.addEventListener=function(e,t){var n=this._events[e],r=this._root;return t?(n||(n=this._events[e]=[],tt[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)},et.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],tt[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},et._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},et.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=V,ve(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},et._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return ye(n),this.setSelection(n),this},et.moveCursorToStart=function(){return this._moveCursorTo(!0)},et.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var nt=function(e){return e._win.getSelection()||null};et.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused){X&&this._win.focus();var t=nt(this);t&&(t.removeAllRanges(),t.addRange(e))}else A.call(this);return this},et.getSelection=function(){var e,t,n,r=nt(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},et.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,H|M,function(e){return Se(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},et.getPath=function(){return this._path};var rt=function(e){for(var t,r,o,a=new n(e,H,function(){return!0},!1);r=a.nextNode();)for(;(o=r.data.indexOf(V))>-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)}};et._didAddZWS=function(){this._hasZWS=!0},et._removeZWS=function(){this._hasZWS&&(rt(this._root),this._hasZWS=!1)},et._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")},et._updatePathOnEvent=function(){var e=this;e._willUpdatePath||(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1,e._updatePath(e.getSelection())},0))},et.focus=function(){return this._root.focus(),this},et.blur=function(){return this._root.blur(),this};var ot="squire-selection-start",it="squire-selection-end";et._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:ot,type:"hidden"}),r=this.createElement("INPUT",{id:it,type:"hidden"});ve(e,n),e.collapse(!1),ve(e,r),n.compareDocumentPosition(r)&U&&(n.id=it,r.id=ot,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},et._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+ot),r=t.querySelector("#"+it);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:he.call(i.childNodes,n),endOffset:he.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},et._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},et._docWasChanged=function(){if(!this._ignoreAllChanges){if(le&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},et._recordUndoState=function(e){if(!this._isInUndoState){var t,n=this._undoIndex+=1,r=this._undoStack,o=this._config.undo,i=o.documentSizeThreshold,a=o.undoLimit;n-1&&2*t.length>i&&a>-1&&n>a&&(r.splice(0,n-a),n=this._undoIndex=a,this._undoStackLength=a),r[n]=t,this._undoStackLength+=1,this._isInUndoState=!0}},et.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._isInUndoState||(this._recordUndoState(e),this._getRangeAndRemoveBookmark(e)),this},et.undo=function(){if(0!==this._undoIndex||!this._isInUndoState){this._recordUndoState(this.getSelection()),this._undoIndex-=1,this._setHTML(this._undoStack[this._undoIndex]);var e=this._getRangeAndRemoveBookmark();e&&this.setSelection(e),this._isInUndoState=!0,this.fireEvent("undoStateChange",{canUndo:0!==this._undoIndex,canRedo:!0}),this.fireEvent("input")}return this},et.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(t>e+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},et.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 Se(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},et.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},et._addFormat=function(e,t,r){var o,i,a,s,d,l,c,h,f=this._root;if(r.collapsed)o=S(this.createElement(e,t),f),ve(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)&&Se(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},et._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var o,a=this._doc;n.collapsed&&(se?(o=a.createTextNode(V),this._didAddZWS()):o=a.createTextNode(""),ve(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(!Se(n,e,!1)){var r,o,i=e.nodeType===I;if(!Se(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 Se(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,_(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},et.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),le||this._docWasChanged(),this):this};var at={DT:"DD",DD:"DT",LI:"LI"},st=function(e,t,n,r){var o=at[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=N(a.ownerDocument,o,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(_(a)),a=t),a};et.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,o=be(n,r),i=Ee(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),le||this._docWasChanged()),this},et.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 Le(t,r),Te(t,r),n=Ce(t,r,r),ve(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=_(o),a=i.childNodes,r=a.length;r--;)s=a[r],C(s,_(s));y(i,this._root),C(o,i)}return e},gt=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},mt=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};et._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},et.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},et._getHTML=function(){return this._root.innerHTML},et._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do S(n,t);while(n=c(n,t));this._ignoreChange=!0},et.getHTML=function(e){var t,n,r,o,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),ae)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,""),ae)for(i=s.length;i--;)v(s[i]);return a&&this._getRangeAndRemoveBookmark(a),o},et.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),o=this._root;r.innerHTML=e,n.appendChild(_(r)),Ke(n),Qe(n,o),y(n,o);for(var i=n;i=c(i,o);)S(i,o);for(this._ignoreChange=!0;t=o.lastChild;)o.removeChild(t);o.appendChild(n),S(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,A.call(this),this._updatePath(a,!0),this},et.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),i(e))ve(t,e),t.setStartAfter(e);else{for(var n,r,o=this._root,a=be(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),ye(t)}return this.focus(),this.setSelection(t),this._updatePath(t),le||this._docWasChanged(),this},et.insertImage=function(e,t){var n=this.createElement("IMG",k({src:e},t));return this.insertElement(n),n};var vt=/\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,Ct=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=vt.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",k({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)};et.insertHTML=function(e,t){var n,r,o,i,a,s,d,l=this.getSelection(),h=this._doc;"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?(i=DOMPurify.sanitize(e,{WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}),i=h.importNode(i,!0)):(t&&(n=e.indexOf(""),r=e.lastIndexOf(""),n>-1&&r>-1&&(e=e.slice(n+20,r))),o=this.createElement("DIV"),o.innerHTML=e,i=h.createDocumentFragment(),i.appendChild(_(o))),this.saveUndoState(l);try{for(a=this._root,s=i,d={fragment:i,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},Ct(i,i,this),Ke(i),Qe(i,null),Ze(i),i.normalize();s=c(s,i);)S(s,null);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Ne(l,d.fragment,a),le||this._docWasChanged(),l.collapse(!1),this._ensureBottomLine()),this.setSelection(l),this._updatePath(l,!0)}catch(f){this.didError(f)}return this};var _t=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};et.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+'="'+_t(l[n])+'"';for(h+=">",r=0,o=a.length;o>r;r+=1)i=a[r],i=_t(i).replace(/ (?= )/g," "),r&&o>r+1&&(i=h+(i||"
")+c),a[r]=i;return this.insertHTML(a.join(""),t)};var Nt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};et.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},et.bold=Nt("changeFormat",{tag:"B"}),et.italic=Nt("changeFormat",{tag:"I"}),et.underline=Nt("changeFormat",{tag:"U"}),et.strikethrough=Nt("changeFormat",{tag:"S"}),et.subscript=Nt("changeFormat",{tag:"SUB"},{tag:"SUP"}),et.superscript=Nt("changeFormat",{tag:"SUP"},{tag:"SUB"}),et.removeBold=Nt("changeFormat",null,{tag:"B"}),et.removeItalic=Nt("changeFormat",null,{tag:"I"}),et.removeUnderline=Nt("changeFormat",null,{tag:"U"}),et.removeStrikethrough=Nt("changeFormat",null,{tag:"S"}),et.removeSubscript=Nt("changeFormat",null,{tag:"SUB"}),et.removeSuperscript=Nt("changeFormat",null,{tag:"SUP"}),et.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;ve(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),k(t,this._config.tagAttributes.a),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},et.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},et.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},et.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},et.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}}:null,{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},et.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},et.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()},et.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},et.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||(Le(e,t),n=t),n.nodeType===I)return this;this.saveUndoState(e),Te(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=he.call(i,g),h=he.call(i,r)+1):(l=he.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),ye(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},et.increaseQuoteLevel=Nt("modifyBlocks",dt),et.decreaseQuoteLevel=Nt("modifyBlocks",lt),et.makeUnorderedList=Nt("modifyBlocks",ft),et.makeOrderedList=Nt("modifyBlocks",ut),et.removeList=Nt("modifyBlocks",pt),et.increaseListLevel=Nt("modifyBlocks",gt),et.decreaseListLevel=Nt("modifyBlocks",mt),"object"==typeof exports?module.exports=L:"function"==typeof define&&define.amd?define(function(){return L}):($.Squire=L,top!==$&&"true"===e.documentElement.getAttribute("data-squireinit")&&($.editor=new L(e),$.onEditorLoad&&($.onEditorLoad($.editor),$.onEditorLoad=null)))}(document); \ No newline at end of file +if(s.nodeType===I)return!1;o=new n(s,H,function(e){return Se(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},et.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},et._addFormat=function(e,t,r){var o,i,a,s,d,l,c,h,f=this._root;if(r.collapsed)o=S(this.createElement(e,t),f),ve(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)&&Se(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},et._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var o,a=this._doc;n.collapsed&&(se?(o=a.createTextNode(V),this._didAddZWS()):o=a.createTextNode(""),ve(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(!Se(n,e,!1)){var r,o,i=e.nodeType===I;if(!Se(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 Se(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,_(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},et.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),le||this._docWasChanged(),this):this};var at={DT:"DD",DD:"DT",LI:"LI"},st=function(e,t,n,r){var o=at[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=N(a.ownerDocument,o,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(_(a)),a=t),a};et.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,o=be(n,r),i=Ee(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),le||this._docWasChanged()),this},et.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 Le(t,r),Te(t,r),n=Ce(t,r,r),ve(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=_(o),a=i.childNodes,r=a.length;r--;)s=a[r],C(s,_(s));y(i,this._root),C(o,i)}return e},gt=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},mt=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};et._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},et.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},et._getHTML=function(){return this._root.innerHTML},et._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do S(n,t);while(n=c(n,t));this._ignoreChange=!0},et.getHTML=function(e){var t,n,r,o,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),ae)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,""),ae)for(i=s.length;i--;)v(s[i]);return a&&this._getRangeAndRemoveBookmark(a),o},et.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),o=this._root;r.innerHTML=e,n.appendChild(_(r)),Ke(n),Qe(n,o),y(n,o);for(var i=n;i=c(i,o);)S(i,o);for(this._ignoreChange=!0;t=o.lastChild;)o.removeChild(t);o.appendChild(n),S(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,A.call(this),this._updatePath(a,!0),this},et.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),i(e))ve(t,e),t.setStartAfter(e);else{for(var n,r,o=this._root,a=be(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),ye(t)}return this.focus(),this.setSelection(t),this._updatePath(t),le||this._docWasChanged(),this},et.insertImage=function(e,t){var n=this.createElement("IMG",k({src:e},t));return this.insertElement(n),n};var vt=/\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,Ct=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=vt.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",k({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)};et.insertHTML=function(e,t){var n,r,o,i,a,s,d,l=this.getSelection(),h=this._doc;"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?(i=DOMPurify.sanitize(e,{WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}),i=h.importNode(i,!0)):(t&&(n=e.indexOf(""),r=e.lastIndexOf(""),n>-1&&r>-1&&(e=e.slice(n+20,r))),o=this.createElement("DIV"),o.innerHTML=e,i=h.createDocumentFragment(),i.appendChild(_(o))),this.saveUndoState(l);try{for(a=this._root,s=i,d={fragment:i,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},Ct(i,i,this),Ke(i),Qe(i,null),Ze(i),i.normalize();s=c(s,i);)S(s,null);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Ne(l,d.fragment,a),le||this._docWasChanged(),l.collapse(!1),this._ensureBottomLine()),this.setSelection(l),this._updatePath(l,!0)}catch(f){this.didError(f)}return this};var _t=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};et.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+'="'+_t(l[n])+'"';for(h+=">",r=0,o=a.length;o>r;r+=1)i=a[r],i=_t(i).replace(/ (?= )/g," "),r&&o>r+1&&(i=h+(i||"
")+c),a[r]=i;return this.insertHTML(a.join(""),t)};var Nt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};et.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},et.bold=Nt("changeFormat",{tag:"B"}),et.italic=Nt("changeFormat",{tag:"I"}),et.underline=Nt("changeFormat",{tag:"U"}),et.strikethrough=Nt("changeFormat",{tag:"S"}),et.subscript=Nt("changeFormat",{tag:"SUB"},{tag:"SUP"}),et.superscript=Nt("changeFormat",{tag:"SUP"},{tag:"SUB"}),et.removeBold=Nt("changeFormat",null,{tag:"B"}),et.removeItalic=Nt("changeFormat",null,{tag:"I"}),et.removeUnderline=Nt("changeFormat",null,{tag:"U"}),et.removeStrikethrough=Nt("changeFormat",null,{tag:"S"}),et.removeSubscript=Nt("changeFormat",null,{tag:"SUB"}),et.removeSuperscript=Nt("changeFormat",null,{tag:"SUP"}),et.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;ve(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),k(t,this._config.tagAttributes.a),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},et.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},et.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},et.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},et.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}}:null,{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},et.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},et.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()},et.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},et.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||(Le(e,t),n=t),n.nodeType===I)return this;this.saveUndoState(e),Te(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=he.call(i,g),h=he.call(i,r)+1):(l=he.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),ye(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},et.increaseQuoteLevel=Nt("modifyBlocks",dt),et.decreaseQuoteLevel=Nt("modifyBlocks",lt),et.makeUnorderedList=Nt("modifyBlocks",ft),et.makeOrderedList=Nt("modifyBlocks",ut),et.removeList=Nt("modifyBlocks",pt),et.increaseListLevel=Nt("modifyBlocks",gt),et.decreaseListLevel=Nt("modifyBlocks",mt),"object"==typeof exports?module.exports=L:"function"==typeof define&&define.amd?define(function(){return L}):($.Squire=L,top!==$&&"true"===e.documentElement.getAttribute("data-squireinit")&&($.editor=new L(e),$.onEditorLoad&&($.onEditorLoad($.editor),$.onEditorLoad=null)))}(document); From ea4e4ca5927e9fb76128f6b60f5fb52fec7d9b56 Mon Sep 17 00:00:00 2001 From: Andy Kauffman Date: Fri, 8 Jul 2016 10:04:48 -0400 Subject: [PATCH 6/6] reset build/squire.js --- build/squire.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/squire.js b/build/squire.js index 058dd83..ebe455b 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&&!!pe[e.nodeName]}function i(e){return ue.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+"]"),o&&(he.call(o,Z)>-1&&(a+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),he.call(o,G)>-1&&(a+="[color="+e.style.color.replace(/ /g,"")+"]"),he.call(o,j)>-1&&(a+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),he.call(o,Q)>-1&&(a+="[fontSize="+e.style.fontSize+"]")))),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 _(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function N(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 S(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=O(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;se&&r&&r.nodeType===I&&!r.data;)e.removeChild(r),r=e.firstChild;r||(se?(n=a.createTextNode(V),O(a)._didAddZWS()):n=a.createTextNode(""))}else if(ae){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=N(a,"BR");(r=e.lastElementChild)&&!i(r);)e=r;if(n)try{e.appendChild(n)}catch(d){O(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=O(l)._config;for(n=0,r=d.length;r>n;n+=1)o=d[n],a="BR"===o.nodeName,!a&&i(o)?(c||(c=N(l,h.blockTag,h.blockAttributes)),c.appendChild(o),n-=1,r-=1):(a||c)&&(c||(c=N(l,h.blockTag,h.blockAttributes)),S(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(S(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));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(_(t)),b(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),ne&&(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=N(a,"DIV"),r.appendChild(_(o)),o.appendChild(r)}v(e),n=!s(e),o.appendChild(_(e)),n&&y(o,t),i&&x(i,t)}else d&&(o=N(a,"DIV"),e.insertBefore(o,i),S(o,t))}function O(e){for(var t,n=Je.length;n--;)if(t=Je[n],t._doc===e)return t;return null}function k(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?k(e[n],r):r;return e}function L(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._isFocused=!1,this._lastSelection=null,de&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"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,le?(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",A),this.addEventListener("mousedown",B),this.addEventListener("touchstart",B),this.addEventListener("focus",D),this._awaitingPaste=!1,this.addEventListener(te?"beforecut":"cut",Ve),this.addEventListener("copy",$e),this.addEventListener(te?"beforepaste":"paste",Ye),this.addEventListener("drop",Xe),this.addEventListener(ne?"keypress":"keydown",Be),this._keyHandlers=Object.create(Pe),this.setConfig(t),te&&(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){}Je.push(this),this.setHTML("")}function A(){this._restoreSelection=!0}function B(){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,z=0,W=1,q=2,K=3,Z="highlight",G="colour",j="font",Q="size",V="​",$=e.defaultView,Y=navigator.userAgent,X=/iP(?:ad|hone|od)/.test(Y),J=/Mac OS X/.test(Y),ee=/Gecko\//.test(Y),te=/Trident\/[456]\./.test(Y),ne=!!$.opera,re=/Edge\//.test(Y),oe=!re&&/WebKit\//.test(Y),ie=J?"meta-":"ctrl-",ae=te||ne,se=te||oe,de=te,le="undefined"!=typeof MutationObserver,ce=/[^ \t\r\n]/,he=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var fe={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(fe[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(fe[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(fe[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var ue=/^(?:#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)$/,pe={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},ge=function(e,t){for(var n=e.childNodes;t&&e.nodeType===P;)e=n[t-1],n=e.childNodes,t=n.length;return e},me=function(e,t){if(e.nodeType===P){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(W,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(z,r)<1,s=e.compareBoundaryPoints(q,r)>-1;return a&&s},ye=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))},Te=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=he.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=he.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},be=function(e,t){var n,r=e.startContainer;return i(r)?n=l(r,t):a(r)?n=r:(n=ge(r,e.startOffset),n=c(n,t)),n&&Se(e,n,!0)?n:null},Ee=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=me(o,e.endOffset),!n||!p(t,n))for(n=t;r=n.lastChild;)n=r;n=l(n,t)}return n&&Se(e,n,!0)?n:null},xe=new n(null,H|M,function(e){return e.nodeType===I?ce.test(e.data):"IMG"===e.nodeName}),Oe=function(e,t){var n,r=e.startContainer,o=e.startOffset;if(xe.root=null,r.nodeType===I){if(o)return!1;n=r}else if(n=me(r,o),n&&!p(t,n)&&(n=null),!n&&(n=ge(r,o),n.nodeType===I&&n.length))return!1;return xe.currentNode=n,xe.root=be(e,t),!xe.previousNode()},ke=function(e,t){var n,r=e.endContainer,o=e.endOffset;if(xe.root=null,r.nodeType===I){if(n=r.data.length,n&&n>o)return!1;xe.currentNode=r}else xe.currentNode=ge(r,o);return xe.root=Ee(e,t),!xe.nextNode()},Le=function(e,t){var n,r=be(e,t),o=Ee(e,t);r&&o&&(n=r.parentNode,e.setStart(n,he.call(n.childNodes,r)),n=o.parentNode,e.setEnd(n,he.call(n.childNodes,o)+1))},Ae={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},Be=function(e){var t=e.keyCode,n=Ae[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),ne&&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),_e(o,this._root),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},De=function(e){return function(t,n){n.preventDefault(),t[e]()}},Re=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)}},Ue=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===V);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,he.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),a(n)||(n=l(n,e._root)),S(n,e._root),ye(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)}},Pe={enter:function(e,t,n){var r,o,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),Ct(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||_e(n,a),r=be(n,a),!r||/^T[HD]$/.test(r.nodeName))return ve(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(mt,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(ct,n)}for(i=st(e,r,n.startContainer,n.startOffset),rt(r),Ze(r),S(r,a);i.nodeType===P;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===V)){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&&!ne)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(Oe(n,r)){t.preventDefault();var o,i=be(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(mt,n);if(u(i,r,"BLOCKQUOTE"))return e.modifyBlocks(lt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Ue(e)},0);else t.preventDefault(),_e(n,r),Ue(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(ke(n,l)){if(t.preventDefault(),r=be(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(),Te(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),ye(n),void Ue(e,n);e.setSelection(i),setTimeout(function(){Ue(e)},0)}else t.preventDefault(),_e(n,l),Ue(e,n)},tab:function(e,t,n){var r,o,i=e._root;if(e._removeZWS(),n.collapsed&&Oe(n,i))for(r=be(n,i);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(gt,n));break}r=o}},"shift-tab":function(e,t,n){var r,o=e._root;e._removeZWS(),n.collapsed&&Oe(n,o)&&(r=n.startContainer,(u(r,o,"UL")||u(r,o,"OL"))&&(t.preventDefault(),e.modifyBlocks(mt,n)))},space:function(e,t,n){var r,o;e._recordUndoState(n),Ct(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()}};J&&ee&&(Pe["meta-left"]=function(e,t){t.preventDefault();var n=nt(e);n&&n.modify&&n.modify("move","backward","lineboundary")},Pe["meta-right"]=function(e,t){t.preventDefault();var n=nt(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),J||(Pe.pageup=function(e){e.moveCursorToStart()},Pe.pagedown=function(e){e.moveCursorToEnd()}),Pe[ie+"b"]=Re("B"),Pe[ie+"i"]=Re("I"),Pe[ie+"u"]=Re("U"),Pe[ie+"shift-7"]=Re("S"),Pe[ie+"shift-5"]=Re("SUB",{tag:"SUP"}),Pe[ie+"shift-6"]=Re("SUP",{tag:"SUB"}),Pe[ie+"shift-8"]=De("makeUnorderedList"),Pe[ie+"shift-9"]=De("makeOrderedList"),Pe[ie+"["]=De("decreaseQuoteLevel"),Pe[ie+"]"]=De("increaseQuoteLevel"),Pe[ie+"y"]=De("redo"),Pe[ie+"z"]=De("undo"),Pe[ie+"shift-z"]=De("redo");var Ie={1:10,2:13,3:16,4:18,5:24,6:32,7:48},we={backgroundColor:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":Z,style:"background-color:"+t})}},color:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":G,style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return N(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return N(e,"I")}},fontFamily:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":j,style:"font-family:"+t})}},fontSize:{regexp:ce,replace:function(e,t){return N(e,"SPAN",{"class":Q,style:"font-size:"+t})}},textDecoration:{regexp:/^underline/i,replace:function(e){return N(e,"U")}}},Fe=function(e){return function(t,n){var r=N(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(_(t)),r}},Me=function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in we)r=we[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),a||(a=s),i&&i.appendChild(s),i=s,e.style[n]="");return a&&(i.appendChild(_(e)),"SPAN"===e.nodeName?t.replaceChild(a,e):e.appendChild(a)),i||e},He={P:Me,SPAN:Me,STRONG:Fe("B"),EM:Fe("I"),INS:Fe("U"),STRIKE:Fe("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=N(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=N(c,"SPAN",{"class":"size",style:"font-size:"+Ie[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=N(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=N(c,"SPAN")),t.replaceChild(a,e),i.appendChild(_(e)),i},TT:function(e,t){var n=N(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(_(e)),n}},ze=/^(?: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)$/,We=/^(?:HEAD|META|STYLE)/,qe=new n(null,H|M,function(){return!0}),Ke=function St(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(qe.root=n,r=0,o=g.length;o>r;r+=1)if(a=g[r],s=a.nodeName,d=a.nodeType,l=He[s],d===P){if(c=a.childNodes.length,l)a=l(a,e);else{if(We.test(s)){e.removeChild(a),r-=1,o-=1;continue}if(!ze.test(s)&&!i(a)){r-=1,o+=c-1,e.replaceChild(_(a),a);continue}}c&&St(a,t||"PRE"===s)}else{if(d===I){if(u=a.data,h=!ce.test(u.charAt(0)),f=!ce.test(u.charAt(u.length-1)),t||!h&&!f)continue;if(h){for(qe.currentNode=a;(p=qe.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(qe.currentNode=a;(p=qe.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},Ze=function yt(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):(yt(t),i(t)&&!t.firstChild&&e.removeChild(t))},Ge=function(e){return e.nodeType===P?"BR"===e.nodeName:ce.test(e.data)},je=function(e){for(var t,r=e.parentNode;i(r);)r=r.parentNode;return t=new n(r,M|H,Ge),t.currentNode=e,!!t.nextNode()},Qe=function(e,t){var n,r,o,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=je(a[n]);for(;d--;)r=a[d],o=r.parentNode,o&&(s[d]?i(o)||y(o,t):v(r))},Ve=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._root,i=this;this.saveUndoState(n),re||X||!t?setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0):(Te(n,o),r.appendChild(_e(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},$e=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");re||X||!t||(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},Ye=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,h=this;if(!re&&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,!re&&o&&(he.call(o,"text/html")>-1||!ee&&he.call(o,"text/plain")>-1&&he.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,_=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(_),u.selectNodeContents(_),this.setSelection(u),setTimeout(function(){try{h._awaitingPaste=!1;for(var e,t,n="",r=_;_=r;)r=_.nextSibling,v(_),e=_.firstChild,e&&e===_.lastChild&&"DIV"===e.nodeName&&(_=e),n+=_.innerHTML;t=h._createRange(p,g,m,C),h.setSelection(t),n&&h.insertHTML(n,!0)}catch(o){h.didError(o)}},0)},Xe=function(e){for(var t=e.dataTransfer.types,n=t.length,r=!1,o=!1;n--;)switch(t[n]){case"text/plain":r=!0;break;case"text/html":o=!0;break;default:return}(o||r)&&this.saveUndoState()},Je=[],et=L.prototype;et.setConfig=function(e){return e=k({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},undo:{documentSizeThreshold:-1,undoLimit:-1}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},et.createElement=function(e,t,n){return N(this._doc,e,t,n)},et.createDefaultBlock=function(e){var t=this._config;return S(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},et.didError=function(e){console.log(e)},et.getDocument=function(){return this._doc},et.getRoot=function(){return this._root},et.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 tt={pathChange:1,select:1,input:1,undoStateChange:1};et.fireEvent=function(e,t){var n,r,o,i=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=p(this._root,this._doc.activeElement),"focus"===e){if(!n||this._isFocused)return this;this._isFocused=!0}else{if(n||!this._isFocused)return this;this._isFocused=!1}if(i)for(t||(t={}),t.type!==e&&(t.type=e),i=i.slice(),r=i.length;r--;){o=i[r];try{o.handleEvent?o.handleEvent(t):o.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},et.destroy=function(){var e,t=Je.length,n=this._events;for(e in n)this.removeEventListener(e);for(this._mutation&&this._mutation.disconnect();t--;)Je[t]===this&&Je.splice(t,1);this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0},et.handleEvent=function(e){this.fireEvent(e.type,e)},et.addEventListener=function(e,t){var n=this._events[e],r=this._root;return t?(n||(n=this._events[e]=[],tt[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)},et.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],tt[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},et._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},et.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=V,ve(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},et._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return ye(n),this.setSelection(n),this},et.moveCursorToStart=function(){return this._moveCursorTo(!0)},et.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var nt=function(e){return e._win.getSelection()||null};et.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused){X&&this._win.focus();var t=nt(this);t&&(t.removeAllRanges(),t.addRange(e))}else A.call(this);return this},et.getSelection=function(){var e,t,n,r=nt(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},et.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,H|M,function(e){return Se(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},et.getPath=function(){return this._path};var rt=function(e){for(var t,r,o,a=new n(e,H,function(){return!0},!1);r=a.nextNode();)for(;(o=r.data.indexOf(V))>-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)}};et._didAddZWS=function(){this._hasZWS=!0},et._removeZWS=function(){this._hasZWS&&(rt(this._root),this._hasZWS=!1)},et._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")},et._updatePathOnEvent=function(){var e=this;e._willUpdatePath||(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1,e._updatePath(e.getSelection())},0))},et.focus=function(){return this._root.focus(),this},et.blur=function(){return this._root.blur(),this};var ot="squire-selection-start",it="squire-selection-end";et._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:ot,type:"hidden"}),r=this.createElement("INPUT",{id:it,type:"hidden"});ve(e,n),e.collapse(!1),ve(e,r),n.compareDocumentPosition(r)&U&&(n.id=it,r.id=ot,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},et._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+ot),r=t.querySelector("#"+it);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:he.call(i.childNodes,n),endOffset:he.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},et._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},et._docWasChanged=function(){if(!this._ignoreAllChanges){if(le&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},et._recordUndoState=function(e){if(!this._isInUndoState){var t,n=this._undoIndex+=1,r=this._undoStack,o=this._config.undo,i=o.documentSizeThreshold,a=o.undoLimit;n-1&&2*t.length>i&&a>-1&&n>a&&(r.splice(0,n-a),n=this._undoIndex=a,this._undoStackLength=a),r[n]=t,this._undoStackLength+=1,this._isInUndoState=!0}},et.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._isInUndoState||(this._recordUndoState(e),this._getRangeAndRemoveBookmark(e)),this},et.undo=function(){if(0!==this._undoIndex||!this._isInUndoState){this._recordUndoState(this.getSelection()),this._undoIndex-=1,this._setHTML(this._undoStack[this._undoIndex]);var e=this._getRangeAndRemoveBookmark();e&&this.setSelection(e),this._isInUndoState=!0,this.fireEvent("undoStateChange",{canUndo:0!==this._undoIndex,canRedo:!0}),this.fireEvent("input")}return this},et.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(t>e+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},et.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 Se(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},et.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},et._addFormat=function(e,t,r){var o,i,a,s,d,l,c,h,f=this._root;if(r.collapsed)o=S(this.createElement(e,t),f),ve(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)&&Se(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},et._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var o,a=this._doc;n.collapsed&&(se?(o=a.createTextNode(V),this._didAddZWS()):o=a.createTextNode(""),ve(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(!Se(n,e,!1)){var r,o,i=e.nodeType===I;if(!Se(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 Se(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,_(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},et.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),le||this._docWasChanged(),this):this};var at={DT:"DD",DD:"DT",LI:"LI"},st=function(e,t,n,r){var o=at[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=N(a.ownerDocument,o,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(_(a)),a=t),a};et.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,o=be(n,r),i=Ee(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),le||this._docWasChanged()),this},et.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 Le(t,r),Te(t,r),n=Ce(t,r,r),ve(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=_(o),a=i.childNodes,r=a.length;r--;)s=a[r],C(s,_(s));y(i,this._root),C(o,i)}return e},gt=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},mt=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};et._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},et.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},et._getHTML=function(){return this._root.innerHTML},et._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do S(n,t);while(n=c(n,t));this._ignoreChange=!0},et.getHTML=function(e){var t,n,r,o,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),ae)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,""),ae)for(i=s.length;i--;)v(s[i]);return a&&this._getRangeAndRemoveBookmark(a),o},et.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),o=this._root;r.innerHTML=e,n.appendChild(_(r)),Ke(n),Qe(n,o),y(n,o);for(var i=n;i=c(i,o);)S(i,o);for(this._ignoreChange=!0;t=o.lastChild;)o.removeChild(t);o.appendChild(n),S(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,A.call(this),this._updatePath(a,!0),this},et.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),i(e))ve(t,e),t.setStartAfter(e);else{for(var n,r,o=this._root,a=be(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),ye(t)}return this.focus(),this.setSelection(t),this._updatePath(t),le||this._docWasChanged(),this},et.insertImage=function(e,t){var n=this.createElement("IMG",k({src:e},t));return this.insertElement(n),n};var vt=/\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,Ct=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=vt.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",k({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)};et.insertHTML=function(e,t){var n,r,o,i,a,s,d,l=this.getSelection(),h=this._doc;"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?(i=DOMPurify.sanitize(e,{WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}),i=h.importNode(i,!0)):(t&&(n=e.indexOf(""),r=e.lastIndexOf(""),n>-1&&r>-1&&(e=e.slice(n+20,r))),o=this.createElement("DIV"),o.innerHTML=e,i=h.createDocumentFragment(),i.appendChild(_(o))),this.saveUndoState(l);try{for(a=this._root,s=i,d={fragment:i,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},Ct(i,i,this),Ke(i),Qe(i,null),Ze(i),i.normalize();s=c(s,i);)S(s,null);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Ne(l,d.fragment,a),le||this._docWasChanged(),l.collapse(!1),this._ensureBottomLine()),this.setSelection(l),this._updatePath(l,!0)}catch(f){this.didError(f)}return this};var _t=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};et.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+'="'+_t(l[n])+'"';for(h+=">",r=0,o=a.length;o>r;r+=1)i=a[r],i=_t(i).replace(/ (?= )/g," "),r&&o>r+1&&(i=h+(i||"
")+c),a[r]=i;return this.insertHTML(a.join(""),t)};var Nt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};et.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},et.bold=Nt("changeFormat",{tag:"B"}),et.italic=Nt("changeFormat",{tag:"I"}),et.underline=Nt("changeFormat",{tag:"U"}),et.strikethrough=Nt("changeFormat",{tag:"S"}),et.subscript=Nt("changeFormat",{tag:"SUB"},{tag:"SUP"}),et.superscript=Nt("changeFormat",{tag:"SUP"},{tag:"SUB"}),et.removeBold=Nt("changeFormat",null,{tag:"B"}),et.removeItalic=Nt("changeFormat",null,{tag:"I"}),et.removeUnderline=Nt("changeFormat",null,{tag:"U"}),et.removeStrikethrough=Nt("changeFormat",null,{tag:"S"}),et.removeSubscript=Nt("changeFormat",null,{tag:"SUB"}),et.removeSuperscript=Nt("changeFormat",null,{tag:"SUP"}),et.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;ve(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),k(t,this._config.tagAttributes.a),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},et.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},et.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},et.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},et.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}}:null,{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},et.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},et.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()},et.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},et.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||(Le(e,t),n=t),n.nodeType===I)return this;this.saveUndoState(e),Te(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=he.call(i,g),h=he.call(i,r)+1):(l=he.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),ye(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},et.increaseQuoteLevel=Nt("modifyBlocks",dt),et.decreaseQuoteLevel=Nt("modifyBlocks",lt),et.makeUnorderedList=Nt("modifyBlocks",ft),et.makeOrderedList=Nt("modifyBlocks",ut),et.removeList=Nt("modifyBlocks",pt),et.increaseListLevel=Nt("modifyBlocks",gt),et.decreaseListLevel=Nt("modifyBlocks",mt),"object"==typeof exports?module.exports=L:"function"==typeof define&&define.amd?define(function(){return L}):($.Squire=L,top!==$&&"true"===e.documentElement.getAttribute("data-squireinit")&&($.editor=new L(e),$.onEditorLoad&&($.onEditorLoad($.editor),$.onEditorLoad=null)))}(document); +!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&&!!pt[e.nodeName]}function i(e){return ut.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+"]"),o&&(ht.call(o,Z)>-1&&(a+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),ht.call(o,G)>-1&&(a+="[color="+e.style.color.replace(/ /g,"")+"]"),ht.call(o,j)>-1&&(a+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),ht.call(o,Q)>-1&&(a+="[fontSize="+e.style.fontSize+"]")))),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 _(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function N(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 S(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=O(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;st&&r&&r.nodeType===I&&!r.data;)e.removeChild(r),r=e.firstChild;r||(st?(n=a.createTextNode(V),O(a)._didAddZWS()):n=a.createTextNode(""))}else if(at){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=N(a,"BR");(r=e.lastElementChild)&&!i(r);)e=r;if(n)try{e.appendChild(n)}catch(d){O(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=O(l)._config;for(n=0,r=d.length;r>n;n+=1)o=d[n],a="BR"===o.nodeName,!a&&i(o)?(c||(c=N(l,h.blockTag,h.blockAttributes)),c.appendChild(o),n-=1,r-=1):(a||c)&&(c||(c=N(l,h.blockTag,h.blockAttributes)),S(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(S(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));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(_(t)),b(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),nt&&(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=N(a,"DIV"),r.appendChild(_(o)),o.appendChild(r)}v(e),n=!s(e),o.appendChild(_(e)),n&&y(o,t),i&&x(i,t)}else d&&(o=N(a,"DIV"),e.insertBefore(o,i),S(o,t))}function O(e){for(var t,n=Jt.length;n--;)if(t=Jt[n],t._doc===e)return t;return null}function k(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?k(e[n],r):r;return e}function L(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._isFocused=!1,this._lastSelection=null,dt&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"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,lt?(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",A),this.addEventListener("mousedown",B),this.addEventListener("touchstart",B),this.addEventListener("focus",D),this._awaitingPaste=!1,this.addEventListener(tt?"beforecut":"cut",Vt),this.addEventListener("copy",$t),this.addEventListener(tt?"beforepaste":"paste",Yt),this.addEventListener("drop",Xt),this.addEventListener(nt?"keypress":"keydown",Bt),this._keyHandlers=Object.create(Pt),this.setConfig(t),tt&&(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 A(){this._restoreSelection=!0}function B(){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,z=0,W=1,q=2,K=3,Z="highlight",G="colour",j="font",Q="size",V="​",$=e.defaultView,Y=navigator.userAgent,X=/iP(?:ad|hone|od)/.test(Y),J=/Mac OS X/.test(Y),et=/Gecko\//.test(Y),tt=/Trident\/[456]\./.test(Y),nt=!!$.opera,rt=/Edge\//.test(Y),ot=!rt&&/WebKit\//.test(Y),it=J?"meta-":"ctrl-",at=tt||nt,st=tt||ot,dt=tt,lt="undefined"!=typeof MutationObserver,ct=/[^ \t\r\n]/,ht=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var ft={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(ft[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(ft[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(ft[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var ut=/^(?:#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)$/,pt={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},gt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===P;)e=n[t-1],n=e.childNodes,t=n.length;return e},mt=function(e,t){if(e.nodeType===P){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(W,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(z,r)<1,s=e.compareBoundaryPoints(q,r)>-1;return a&&s},yt=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))},Tt=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=ht.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=ht.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},bt=function(e,t){var n,r=e.startContainer;return i(r)?n=l(r,t):a(r)?n=r:(n=gt(r,e.startOffset),n=c(n,t)),n&&St(e,n,!0)?n:null},Et=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=mt(o,e.endOffset),!n||!p(t,n))for(n=t;r=n.lastChild;)n=r;n=l(n,t)}return n&&St(e,n,!0)?n:null},xt=new n(null,H|M,function(e){return e.nodeType===I?ct.test(e.data):"IMG"===e.nodeName}),Ot=function(e,t){var n,r=e.startContainer,o=e.startOffset;if(xt.root=null,r.nodeType===I){if(o)return!1;n=r}else if(n=mt(r,o),n&&!p(t,n)&&(n=null),!n&&(n=gt(r,o),n.nodeType===I&&n.length))return!1;return xt.currentNode=n,xt.root=bt(e,t),!xt.previousNode()},kt=function(e,t){var n,r=e.endContainer,o=e.endOffset;if(xt.root=null,r.nodeType===I){if(n=r.data.length,n&&n>o)return!1;xt.currentNode=r}else xt.currentNode=gt(r,o);return xt.root=Et(e,t),!xt.nextNode()},Lt=function(e,t){var n,r=bt(e,t),o=Et(e,t);r&&o&&(n=r.parentNode,e.setStart(n,ht.call(n.childNodes,r)),n=o.parentNode,e.setEnd(n,ht.call(n.childNodes,o)+1))},At={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},Bt=function(e){var t=e.keyCode,n=At[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),nt&&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),_t(o,this._root),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},Dt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Rt=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)}},Ut=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===V);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,ht.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),a(n)||(n=l(n,e._root)),S(n,e._root),yt(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)}},Pt={enter:function(e,t,n){var r,o,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),_n(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||_t(n,a),r=bt(n,a),!r||/^T[HD]$/.test(r.nodeName))return vt(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(vn,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(hn,n)}for(i=dn(e,r,n.startContainer,n.startOffset),rn(r),Zt(r),S(r,a);i.nodeType===P;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===V)){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&&!nt)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(Ot(n,r)){t.preventDefault();var o,i=bt(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(vn,n);if(u(i,r,"BLOCKQUOTE"))return e.modifyBlocks(cn,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Ut(e)},0);else t.preventDefault(),_t(n,r),Ut(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(kt(n,l)){if(t.preventDefault(),r=bt(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(),Tt(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),yt(n),void Ut(e,n);e.setSelection(i),setTimeout(function(){Ut(e)},0)}else t.preventDefault(),_t(n,l),Ut(e,n)},tab:function(e,t,n){var r,o,i=e._root;if(e._removeZWS(),n.collapsed&&Ot(n,i))for(r=bt(n,i);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(mn,n));break}r=o}},"shift-tab":function(e,t,n){var r,o=e._root;e._removeZWS(),n.collapsed&&Ot(n,o)&&(r=n.startContainer,(u(r,o,"UL")||u(r,o,"OL"))&&(t.preventDefault(),e.modifyBlocks(vn,n)))},space:function(e,t,n){var r,o;e._recordUndoState(n),_n(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()}};J&&et&&(Pt["meta-left"]=function(e,t){t.preventDefault();var n=nn(e);n&&n.modify&&n.modify("move","backward","lineboundary")},Pt["meta-right"]=function(e,t){t.preventDefault();var n=nn(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),J||(Pt.pageup=function(e){e.moveCursorToStart()},Pt.pagedown=function(e){e.moveCursorToEnd()}),Pt[it+"b"]=Rt("B"),Pt[it+"i"]=Rt("I"),Pt[it+"u"]=Rt("U"),Pt[it+"shift-7"]=Rt("S"),Pt[it+"shift-5"]=Rt("SUB",{tag:"SUP"}),Pt[it+"shift-6"]=Rt("SUP",{tag:"SUB"}),Pt[it+"shift-8"]=Dt("makeUnorderedList"),Pt[it+"shift-9"]=Dt("makeOrderedList"),Pt[it+"["]=Dt("decreaseQuoteLevel"),Pt[it+"]"]=Dt("increaseQuoteLevel"),Pt[it+"y"]=Dt("redo"),Pt[it+"z"]=Dt("undo"),Pt[it+"shift-z"]=Dt("redo");var It={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:ct,replace:function(e,t){return N(e,"SPAN",{"class":Z,style:"background-color:"+t})}},color:{regexp:ct,replace:function(e,t){return N(e,"SPAN",{"class":G,style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return N(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return N(e,"I")}},fontFamily:{regexp:ct,replace:function(e,t){return N(e,"SPAN",{"class":j,style:"font-family:"+t})}},fontSize:{regexp:ct,replace:function(e,t){return N(e,"SPAN",{"class":Q,style:"font-size:"+t})}},textDecoration:{regexp:/^underline/i,replace:function(e){return N(e,"U")}}},Ft=function(e){return function(t,n){var r=N(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(_(t)),r}},Mt=function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),a||(a=s),i&&i.appendChild(s),i=s,e.style[n]="");return a&&(i.appendChild(_(e)),"SPAN"===e.nodeName?t.replaceChild(a,e):e.appendChild(a)),i||e},Ht={P:Mt,SPAN:Mt,STRONG:Ft("B"),EM:Ft("I"),INS:Ft("U"),STRIKE:Ft("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=N(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=N(c,"SPAN",{"class":"size",style:"font-size:"+It[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=N(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=N(c,"SPAN")),t.replaceChild(a,e),i.appendChild(_(e)),i},TT:function(e,t){var n=N(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(_(e)),n}},zt=/^(?: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)/,qt=new n(null,H|M,function(){return!0}),Kt=function yn(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(qt.root=n,r=0,o=g.length;o>r;r+=1)if(a=g[r],s=a.nodeName,d=a.nodeType,l=Ht[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(!zt.test(s)&&!i(a)){r-=1,o+=c-1,e.replaceChild(_(a),a);continue}}c&&yn(a,t||"PRE"===s)}else{if(d===I){if(u=a.data,h=!ct.test(u.charAt(0)),f=!ct.test(u.charAt(u.length-1)),t||!h&&!f)continue;if(h){for(qt.currentNode=a;(p=qt.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(qt.currentNode=a;(p=qt.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},Zt=function Tn(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):(Tn(t),i(t)&&!t.firstChild&&e.removeChild(t))},Gt=function(e){return e.nodeType===P?"BR"===e.nodeName:ct.test(e.data)},jt=function(e){for(var t,r=e.parentNode;i(r);)r=r.parentNode;return t=new n(r,M|H,Gt),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]=jt(a[n]);for(;d--;)r=a[d],o=r.parentNode,o&&(s[d]?i(o)||y(o,t):v(r))},Vt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._root,i=this;this.saveUndoState(n),rt||X||!t?setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0):(Tt(n,o),r.appendChild(_t(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},$t=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");rt||X||!t||(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},Yt=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,h=this;if(!rt&&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,!rt&&o&&(ht.call(o,"text/html")>-1||!et&&ht.call(o,"text/plain")>-1&&ht.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,_=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(_),u.selectNodeContents(_),this.setSelection(u),setTimeout(function(){try{h._awaitingPaste=!1;for(var e,t,n="",r=_;_=r;)r=_.nextSibling,v(_),e=_.firstChild,e&&e===_.lastChild&&"DIV"===e.nodeName&&(_=e),n+=_.innerHTML;t=h._createRange(p,g,m,C),h.setSelection(t),n&&h.insertHTML(n,!0)}catch(o){h.didError(o)}},0)},Xt=function(e){for(var t=e.dataTransfer.types,n=t.length,r=!1,o=!1;n--;)switch(t[n]){case"text/plain":r=!0;break;case"text/html":o=!0;break;default:return}(o||r)&&this.saveUndoState()},Jt=[],en=L.prototype;en.setConfig=function(e){return e=k({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},undo:{documentSizeThreshold:-1,undoLimit:-1}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},en.createElement=function(e,t,n){return N(this._doc,e,t,n)},en.createDefaultBlock=function(e){var t=this._config;return S(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},en.didError=function(e){console.log(e)},en.getDocument=function(){return this._doc},en.getRoot=function(){return this._root},en.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 tn={pathChange:1,select:1,input:1,undoStateChange:1};en.fireEvent=function(e,t){var n,r,o,i=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=p(this._root,this._doc.activeElement),"focus"===e){if(!n||this._isFocused)return this;this._isFocused=!0}else{if(n||!this._isFocused)return this;this._isFocused=!1}if(i)for(t||(t={}),t.type!==e&&(t.type=e),i=i.slice(),r=i.length;r--;){o=i[r];try{o.handleEvent?o.handleEvent(t):o.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},en.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);this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0},en.handleEvent=function(e){this.fireEvent(e.type,e)},en.addEventListener=function(e,t){var n=this._events[e],r=this._root;return t?(n||(n=this._events[e]=[],tn[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)},en.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],tn[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},en._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},en.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=V,vt(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},en._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return yt(n),this.setSelection(n),this},en.moveCursorToStart=function(){return this._moveCursorTo(!0)},en.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var nn=function(e){return e._win.getSelection()||null};en.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused){X&&this._win.focus();var t=nn(this);t&&(t.removeAllRanges(),t.addRange(e))}else A.call(this);return this},en.getSelection=function(){var e,t,n,r=nn(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},en.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,H|M,function(e){return St(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},en.getPath=function(){return this._path};var rn=function(e){for(var t,r,o,a=new n(e,H,function(){return!0},!1);r=a.nextNode();)for(;(o=r.data.indexOf(V))>-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)}};en._didAddZWS=function(){this._hasZWS=!0},en._removeZWS=function(){this._hasZWS&&(rn(this._root),this._hasZWS=!1)},en._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")},en._updatePathOnEvent=function(){var e=this;e._willUpdatePath||(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1,e._updatePath(e.getSelection())},0))},en.focus=function(){return this._root.focus(),this},en.blur=function(){return this._root.blur(),this};var on="squire-selection-start",an="squire-selection-end";en._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:on,type:"hidden"}),r=this.createElement("INPUT",{id:an,type:"hidden"});vt(e,n),e.collapse(!1),vt(e,r),n.compareDocumentPosition(r)&U&&(n.id=an,r.id=on,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},en._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+on),r=t.querySelector("#"+an);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:ht.call(i.childNodes,n),endOffset:ht.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},en._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},en._docWasChanged=function(){if(!this._ignoreAllChanges){if(lt&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},en._recordUndoState=function(e){if(!this._isInUndoState){var t,n=this._undoIndex+=1,r=this._undoStack,o=this._config.undo,i=o.documentSizeThreshold,a=o.undoLimit;n-1&&2*t.length>i&&a>-1&&n>a&&(r.splice(0,n-a),n=this._undoIndex=a,this._undoStackLength=a),r[n]=t,this._undoStackLength+=1,this._isInUndoState=!0}},en.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._isInUndoState||(this._recordUndoState(e),this._getRangeAndRemoveBookmark(e)),this},en.undo=function(){if(0!==this._undoIndex||!this._isInUndoState){this._recordUndoState(this.getSelection()),this._undoIndex-=1,this._setHTML(this._undoStack[this._undoIndex]);var e=this._getRangeAndRemoveBookmark();e&&this.setSelection(e),this._isInUndoState=!0,this.fireEvent("undoStateChange",{canUndo:0!==this._undoIndex,canRedo:!0}),this.fireEvent("input")}return this},en.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(t>e+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},en.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 St(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},en.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},en._addFormat=function(e,t,r){var o,i,a,s,d,l,c,h,f=this._root;if(r.collapsed)o=S(this.createElement(e,t),f),vt(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)&&St(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},en._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var o,a=this._doc;n.collapsed&&(st?(o=a.createTextNode(V),this._didAddZWS()):o=a.createTextNode(""),vt(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(!St(n,e,!1)){var r,o,i=e.nodeType===I;if(!St(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 St(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,_(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},en.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),lt||this._docWasChanged(),this):this};var sn={DT:"DD",DD:"DT",LI:"LI"},dn=function(e,t,n,r){var o=sn[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=N(a.ownerDocument,o,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(_(a)),a=t),a};en.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,o=bt(n,r),i=Et(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),lt||this._docWasChanged()),this},en.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 Lt(t,r),Tt(t,r),n=Ct(t,r,r),vt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=_(o),a=i.childNodes,r=a.length;r--;)s=a[r],C(s,_(s));y(i,this._root),C(o,i)}return e},mn=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},vn=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};en._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},en.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},en._getHTML=function(){return this._root.innerHTML},en._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do S(n,t);while(n=c(n,t));this._ignoreChange=!0},en.getHTML=function(e){var t,n,r,o,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),at)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,""),at)for(i=s.length;i--;)v(s[i]);return a&&this._getRangeAndRemoveBookmark(a),o},en.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),o=this._root;r.innerHTML=e,n.appendChild(_(r)),Kt(n),Qt(n,o),y(n,o);for(var i=n;i=c(i,o);)S(i,o);for(this._ignoreChange=!0;t=o.lastChild;)o.removeChild(t);o.appendChild(n),S(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,A.call(this),this._updatePath(a,!0),this},en.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),i(e))vt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._root,a=bt(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),yt(t)}return this.focus(),this.setSelection(t),this._updatePath(t),lt||this._docWasChanged(),this},en.insertImage=function(e,t){var n=this.createElement("IMG",k({src:e},t));return this.insertElement(n),n};var Cn=/\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,_n=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=Cn.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",k({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)};en.insertHTML=function(e,t){var n,r,o,i,a,s,d,l=this.getSelection(),h=this._doc;"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?(i=DOMPurify.sanitize(e,{WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}),i=h.importNode(i,!0)):(t&&(n=e.indexOf(""),r=e.lastIndexOf(""),n>-1&&r>-1&&(e=e.slice(n+20,r))),o=this.createElement("DIV"),o.innerHTML=e,i=h.createDocumentFragment(),i.appendChild(_(o))),this.saveUndoState(l);try{for(a=this._root,s=i,d={fragment:i,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},_n(i,i,this),Kt(i),Qt(i,null),Zt(i),i.normalize();s=c(s,i);)S(s,null);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Nt(l,d.fragment,a),lt||this._docWasChanged(),l.collapse(!1),this._ensureBottomLine()),this.setSelection(l),this._updatePath(l,!0)}catch(f){this.didError(f)}return this};var Nn=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};en.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+'="'+Nn(l[n])+'"';for(h+=">",r=0,o=a.length;o>r;r+=1)i=a[r],i=Nn(i).replace(/ (?= )/g," "),r&&o>r+1&&(i=h+(i||"
")+c),a[r]=i;return this.insertHTML(a.join(""),t)};var Sn=function(e,t,n){return function(){return this[e](t,n),this.focus()}};en.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},en.bold=Sn("changeFormat",{tag:"B"}),en.italic=Sn("changeFormat",{tag:"I"}),en.underline=Sn("changeFormat",{tag:"U"}),en.strikethrough=Sn("changeFormat",{tag:"S"}),en.subscript=Sn("changeFormat",{tag:"SUB"},{tag:"SUP"}),en.superscript=Sn("changeFormat",{tag:"SUP"},{tag:"SUB"}),en.removeBold=Sn("changeFormat",null,{tag:"B"}),en.removeItalic=Sn("changeFormat",null,{tag:"I"}),en.removeUnderline=Sn("changeFormat",null,{tag:"U"}),en.removeStrikethrough=Sn("changeFormat",null,{tag:"S"}),en.removeSubscript=Sn("changeFormat",null,{tag:"SUB"}),en.removeSuperscript=Sn("changeFormat",null,{tag:"SUP"}),en.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;vt(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),k(t,this._config.tagAttributes.a),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},en.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},en.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},en.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},en.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}}:null,{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},en.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},en.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()},en.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},en.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||(Lt(e,t),n=t),n.nodeType===I)return this;this.saveUndoState(e),Tt(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=ht.call(i,g),h=ht.call(i,r)+1):(l=ht.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),yt(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},en.increaseQuoteLevel=Sn("modifyBlocks",ln),en.decreaseQuoteLevel=Sn("modifyBlocks",cn),en.makeUnorderedList=Sn("modifyBlocks",un),en.makeOrderedList=Sn("modifyBlocks",pn),en.removeList=Sn("modifyBlocks",gn),en.increaseListLevel=Sn("modifyBlocks",mn),en.decreaseListLevel=Sn("modifyBlocks",vn),"object"==typeof exports?module.exports=L:"function"==typeof define&&define.amd?define(function(){return L}):($.Squire=L,top!==$&&"true"===e.documentElement.getAttribute("data-squireinit")&&($.editor=new L(e),$.onEditorLoad&&($.onEditorLoad($.editor),$.onEditorLoad=null)))}(document); \ No newline at end of file