!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function o(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function i(e){return e.nodeType===w&&!!Ce[e.nodeName]}function r(e){switch(e.nodeType){case F:return Se;case w:case H:if(pe&&be.has(e))return be.get(e);break;default:return Ne}var t;return t=o(e.childNodes,a)?_e.test(e.nodeName)?Se:ye:Te,pe&&be.set(e,t),t}function a(e){return r(e)===Se}function s(e){return r(e)===ye}function d(e){return r(e)===Te}function l(e,t){var o=new n(t,z,s);return o.currentNode=e,o}function c(e,t){return e=l(e,t).previousNode(),e!==t?e:null}function h(e,t){return e=l(e,t).nextNode(),e!==t?e:null}function u(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 o in n)if(e.getAttribute(o)!==n[o])return!1;return!0}function p(e,t,n,o){for(;e&&e!==t;){if(f(e,n,o))return e;e=e.parentNode}return null}function g(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function m(e,t){var n,o,i,r,a="";return e&&e!==t&&(a=m(e.parentNode,t),e.nodeType===w&&(a+=(a?">":"")+e.nodeName,(n=e.id)&&(a+="#"+n),(o=e.className.trim())&&(i=o.split(/\s\s*/),i.sort(),a+=".",a+=i.join(".")),(r=e.dir)&&(a+="[dir="+r+"]"),i&&(me.call(i,j)>-1&&(a+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),me.call(i,Q)>-1&&(a+="[color="+e.style.color.replace(/ /g,"")+"]"),me.call(i,V)>-1&&(a+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),me.call(i,$)>-1&&(a+="[fontSize="+e.style.fontSize+"]")))),a}function v(e){var t=e.nodeType;return t===w?e.childNodes.length:e.length||0}function _(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,o=n?n.length:0;o--;)t.appendChild(e.firstChild);return t}function S(e,n,o,i){var r,a,s,d,l=e.createElement(n);if(o instanceof Array&&(i=o,o=null),o)for(r in o)a=o[r],a!==t&&l.setAttribute(r,o[r]);if(i)for(s=0,d=i.length;ss?t.startOffset-=1:t.startOffset===s&&(t.startContainer=o,t.startOffset=v(o))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=o,t.endOffset=v(o))),_(n),n.nodeType===F?o.appendData(n.data):d.push(N(n));else if(n.nodeType===w){for(i=d.length;i--;)n.appendChild(d.pop());E(n,t)}}function k(e,t){if(e.nodeType===F&&(e=e.parentNode),e.nodeType===w){var n={startContainer:t.startContainer,startOffset:t.startOffset,endContainer:t.endContainer,endOffset:t.endOffset};E(e,n),t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)}}function B(e,t,n){for(var o,i,r=t;1===r.parentNode.childNodes.length;)r=r.parentNode;_(r),i=e.childNodes.length,o=e.lastChild,o&&"BR"===o.nodeName&&(e.removeChild(o),i-=1),e.appendChild(N(t)),n.setStart(e,i),n.collapse(!0),k(e,n),re&&(o=e.lastChild)&&"BR"===o.nodeName&&e.removeChild(o)}function x(e,t){var n,o,i=e.previousSibling,r=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||r&&/^[OU]L$/.test(r.nodeName))if(i&&u(i,e)){if(!d(i)){if(!s)return;o=S(a,"DIV"),o.appendChild(N(i)),i.appendChild(o)}_(e),n=!d(e),i.appendChild(N(e)),n&&T(i,t),r&&x(r,t)}else s&&(i=S(a,"DIV"),e.insertBefore(i,r),y(i,t))}function L(e){this.isShiftDown=e.shiftKey}function A(e,t,n){var o,i;if(e||(e={}),t)for(o in t)!n&&o in e||(i=t[o],e[o]=i&&i.constructor===Object?A(e[o],i,n):i);return e}function O(e,t){e.nodeType===M&&(e=e.body);var n,o=e.ownerDocument,i=o.defaultView;this._win=i,this._doc=o,this._root=e,this._events={},this._isFocused=!1,this._lastSelection=null,ue&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"onselectionchange"in o?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,fe?(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",D),this.addEventListener("mousedown",R),this.addEventListener("touchstart",R),this.addEventListener("focus",U),this._awaitingPaste=!1,this.addEventListener(ie?"beforecut":"cut",at),this.addEventListener("copy",st),this.addEventListener("keydown",L),this.addEventListener("keyup",L),this.addEventListener(ie?"beforepaste":"paste",dt),this.addEventListener("drop",lt),this.addEventListener(re?"keypress":"keydown",ze),this._keyHandlers=Object.create(Ge),this.setConfig(t),ie&&(i.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,o=this.parentNode,i=this.length-e;return n?o.insertBefore(t,n):o.appendChild(t),i&&this.deleteData(e,i),t}),e.setAttribute("contenteditable","true");try{o.execCommand("enableObjectResizing",!1,"false"),o.execCommand("enableInlineTableEditing",!1,"false")}catch(e){}e.__squire__=this,this.setHTML("")}function D(){this._restoreSelection=!0}function R(){this._restoreSelection=!1}function U(){this._restoreSelection&&this.setSelection(this._lastSelection)}function P(e,t,n){var o,i;for(o=t.firstChild;o;o=i){if(i=o.nextSibling,a(o)){if(o.nodeType===F||"BR"===o.nodeName||"IMG"===o.nodeName){n.appendChild(o);continue}}else if(s(o)){n.appendChild(e.createDefaultBlock([P(e,o,e._doc.createDocumentFragment())]));continue}P(e,o,n)}return n}var I=2,w=1,F=3,M=9,H=11,z=1,W=4,q=0,K=1,G=2,Z=3,j="highlight",Q="colour",V="font",$="size",Y="​",X=e.defaultView,J=navigator.userAgent,ee=/iP(?:ad|hone|od)/.test(J),te=/Mac OS X/.test(J),ne=/Android/.test(J),oe=/Gecko\//.test(J),ie=/Trident\/[456]\./.test(J),re=!!X.opera,ae=/Edge\//.test(J),se=!ae&&/WebKit\//.test(J),de=/Trident\/[4567]\./.test(J),le=te?"meta-":"ctrl-",ce=ie||re,he=ie||se,ue=ie,fe="undefined"!=typeof MutationObserver,pe="undefined"!=typeof WeakMap,ge=/[^ \t\r\n]/,me=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var ve={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,o=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(ve[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,o=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(ve[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,o=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(ve[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}};var _e=/^(?:#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])?|TIME|U|VAR|WBR)$/,Ce={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},Ne=0,Se=1,ye=2,Te=3,be=pe?new WeakMap:null,Ee=function(e,t){for(var n=e.childNodes;t&&e.nodeType===w;)e=n[t-1],n=e.childNodes,t=n.length;return e},ke=function(e,t){if(e.nodeType===w){var n=e.childNodes;if(t-1,r=e.compareBoundaryPoints(K,o)<1;return!i&&!r}var a=e.compareBoundaryPoints(q,o)<1,s=e.compareBoundaryPoints(G,o)>-1;return a&&s},De=function(e){for(var t,n=e.startContainer,o=e.startOffset,r=e.endContainer,a=e.endOffset,s=!0;n.nodeType!==F&&(t=n.childNodes[o],t&&!i(t));)n=t,o=0;if(a)for(;r.nodeType!==F;){if(t=r.childNodes[a-1],!t||i(t)){if(s&&t&&"BR"===t.nodeName){a-=1,s=!1;continue}break}r=t,a=v(r)}else for(;r.nodeType!==F&&(t=r.firstChild,t&&!i(t));)r=t;e.collapsed?(e.setStart(r,a),e.setEnd(n,o)):(e.setStart(n,o),e.setEnd(r,a))},Re=function(e,t){var n,o=e.startContainer,i=e.startOffset,r=e.endContainer,a=e.endOffset,s=!0;for(t||(t=e.commonAncestorContainer);o!==t&&!i;)n=o.parentNode,i=me.call(n.childNodes,o),o=n;for(;;){if(s&&r.nodeType!==F&&r.childNodes[a]&&"BR"===r.childNodes[a].nodeName&&(a+=1,s=!1),r===t||a!==v(r))break;n=r.parentNode,a=me.call(n.childNodes,r)+1,r=n}e.setStart(o,i),e.setEnd(r,a)},Ue=function(e,t){var n,o=e.startContainer;return a(o)?n=c(o,t):o!==t&&s(o)?n=o:(n=Ee(o,e.startOffset),n=h(n,t)),n&&Oe(e,n,!0)?n:null},Pe=function(e,t){var n,o,i=e.endContainer;if(a(i))n=c(i,t);else if(i!==t&&s(i))n=i;else{if(n=ke(i,e.endOffset),!n||!g(t,n))for(n=t;o=n.lastChild;)n=o;n=c(n,t)}return n&&Oe(e,n,!0)?n:null},Ie=new n(null,W|z,function(e){return e.nodeType===F?ge.test(e.data):"IMG"===e.nodeName}),we=function(e,t){var n,o=e.startContainer,i=e.startOffset;if(Ie.root=null,o.nodeType===F){if(i)return!1;n=o}else if(n=ke(o,i),n&&!g(t,n)&&(n=null),!n&&(n=Ee(o,i),n.nodeType===F&&n.length))return!1;return Ie.currentNode=n,Ie.root=Ue(e,t),!Ie.previousNode()},Fe=function(e,t){var n,o=e.endContainer,i=e.endOffset;if(Ie.root=null,o.nodeType===F){if(n=o.data.length,n&&i-1||!oe&&me.call(i,"text/plain")>-1&&me.call(i,"text/rtf")<0))return e.preventDefault(),void(!d&&(r=a.getData("text/html"))?this.insertHTML(r,!0):((r=a.getData("text/plain"))||(r=a.getData("text/uri-list")))&&this.insertPlainText(r,!0));this._awaitingPaste=!0;var f=this._doc.body,p=this.getSelection(),g=p.startContainer,m=p.startOffset,v=p.endContainer,C=p.endOffset,N=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(N),p.selectNodeContents(N),this.setSelection(p),setTimeout(function(){try{u._awaitingPaste=!1;for(var e,t,n="",o=N;N=o;)o=N.nextSibling,_(N),e=N.firstChild,e&&e===N.lastChild&&"DIV"===e.nodeName&&(N=e),n+=N.innerHTML;t=u._createRange(g,m,v,C),u.setSelection(t),n&&u.insertHTML(n,!0)}catch(e){u.didError(e)}},0)},lt=function(e){for(var t=e.dataTransfer.types,n=t.length,o=!1,i=!1;n--;)switch(t[n]){case"text/plain":o=!0;break;case"text/html":i=!0;break;default:return}(i||o)&&this.saveUndoState()},ct=O.prototype,ht=function(t){var n=DOMPurify.sanitize(t,{WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0});return e.importNode(n,!0)};ct.setConfig=function(e){return e=A({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},leafNodeNames:Ce,undo:{documentSizeThreshold:-1,undoLimit:-1},isInsertedHTMLSanitized:!0,isSetHTMLSanitized:!0,sanitizeToDOMFragment:"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?ht:null},e,!0),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},ct.createElement=function(e,t,n){return S(this._doc,e,t,n)},ct.createDefaultBlock=function(e){var t=this._config;return y(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},ct.didError=function(e){console.log(e)},ct.getDocument=function(){return this._doc},ct.getRoot=function(){return this._root},ct.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}),this._ignoreChange=!1)};var ut={pathChange:1,select:1,input:1,undoStateChange:1};ct.fireEvent=function(e,t){var n,o,i,r=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=g(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(r)for(t||(t={}),t.type!==e&&(t.type=e),r=r.slice(),o=r.length;o--;){i=r[o];try{i.handleEvent?i.handleEvent(t):i.call(this,t)}catch(t){t.details="Squire: fireEvent error. Event type: "+e,this.didError(t)}}return this},ct.destroy=function(){var e,t=this._events;for(e in t)this.removeEventListener(e);this._mutation&&this._mutation.disconnect(),delete this._root.__squire__,this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0},ct.handleEvent=function(e){this.fireEvent(e.type,e)},ct.addEventListener=function(e,t){var n=this._events[e],o=this._root;return t?(n||(n=this._events[e]=[],ut[e]||("selectionchange"===e&&(o=this._doc),o.addEventListener(e,this,!0))),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},ct.removeEventListener=function(e,t){var n,o=this._events[e],i=this._root;if(o){if(t)for(n=o.length;n--;)o[n]===t&&o.splice(n,1);else o.length=0;o.length||(delete this._events[e],ut[e]||("selectionchange"===e&&(i=this._doc),i.removeEventListener(e,this,!0)))}return this},ct._createRange=function(e,t,n,o){if(e instanceof this._win.Range)return e.cloneRange();var i=this._doc.createRange();return i.setStart(e,t),n?i.setEnd(n,o):i.setEnd(e,t),i},ct.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,o=e.getBoundingClientRect();return o&&!o.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=Y,Be(e,t),o=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),k(n,e)),o},ct._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return De(n),this.setSelection(n),this},ct.moveCursorToStart=function(){return this._moveCursorTo(!0)},ct.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var ft=function(e){return e._win.getSelection()||null};ct.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused)if(ne&&!this._restoreSelection)D.call(this),this.blur(),this.focus();else{ee&&this._win.focus();var t=ft(this);t&&(t.removeAllRanges(),t.addRange(e))}else D.call(this);return this},ct.getSelection=function(){var e,t,n,o=ft(this),r=this._root;return o&&o.rangeCount&&(e=o.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&i(t)&&e.setStartBefore(t),n&&i(n)&&e.setEndBefore(n)),e&&g(r,e.commonAncestorContainer)?this._lastSelection=e:e=this._lastSelection,e||(e=this._createRange(r.firstChild,0)),e},ct.getSelectedText=function(){var e,t=this.getSelection(),o=new n(t.commonAncestorContainer,W|z,function(e){return Oe(t,e,!0)}),i=t.startContainer,r=t.endContainer,s=o.currentNode=i,d="",l=!1;for(o.filter(s)||(s=o.nextNode());s;)s.nodeType===F?(e=s.data,e&&/\S/.test(e)&&(s===r&&(e=e.slice(0,t.endOffset)),s===i&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===s.nodeName||l&&!a(s))&&(d+="\n",l=!1),s=o.nextNode();return d},ct.getPath=function(){return this._path};var pt=function(e,t){for(var o,i,r,s=new n(e,W,function(){return!0},!1);i=s.nextNode();)for(;(r=i.data.indexOf(Y))>-1&&(!t||i.parentNode!==t);){if(1===i.length){do o=i.parentNode,o.removeChild(i),i=o,s.currentNode=o;while(a(i)&&!v(i));break}i.deleteData(r,1)}};ct._didAddZWS=function(){this._hasZWS=!0},ct._removeZWS=function(){this._hasZWS&&(pt(this._root),this._hasZWS=!1)},ct._updatePath=function(e,t){var n,o=e.startContainer,i=e.endContainer;(t||o!==this._lastAnchorNode||i!==this._lastFocusNode)&&(this._lastAnchorNode=o,this._lastFocusNode=i,n=o&&i?o===i?m(i,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},ct._updatePathOnEvent=function(){var e=this;e._willUpdatePath||(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1,e._updatePath(e.getSelection())},0))},ct.focus=function(){return this._root.focus(),de&&this.fireEvent("focus"),this},ct.blur=function(){return this._root.blur(),de&&this.fireEvent("blur"),this};var gt="squire-selection-start",mt="squire-selection-end";ct._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:gt,type:"hidden"}),o=this.createElement("INPUT",{id:mt,type:"hidden"});Be(e,n),e.collapse(!1),Be(e,o),n.compareDocumentPosition(o)&I&&(n.id=mt,o.id=gt,t=n,n=o,o=t),e.setStartAfter(n),e.setEndBefore(o)},ct._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+gt),o=t.querySelector("#"+mt);if(n&&o){var i=n.parentNode,r=o.parentNode,a=me.call(i.childNodes,n),s=me.call(r.childNodes,o);i===r&&(s-=1),_(n),_(o),e||(e=this._doc.createRange()),e.setStart(i,a),e.setEnd(r,s),k(i,e),i!==r&&k(r,e),e.collapsed&&(i=e.startContainer,i.nodeType===F&&(r=i.childNodes[e.startOffset],r&&r.nodeType===F||(r=i.childNodes[e.startOffset-1]),r&&r.nodeType===F&&(e.setStart(r,0),e.collapse(!0))))}return e||null},ct._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(t<16||t>20)||!(t<33||t>45)||this._docWasChanged()},ct._docWasChanged=function(){if(pe&&(be=new WeakMap),!this._ignoreAllChanges){if(fe&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},ct._recordUndoState=function(e){if(!this._isInUndoState){var t,n=this._undoIndex+=1,o=this._undoStack,i=this._config.undo,r=i.documentSizeThreshold,a=i.undoLimit;n-1&&2*t.length>r&&a>-1&&n>a&&(o.splice(0,n-a),n=this._undoIndex=a,this._undoStackLength=a),o[n]=t, this._undoStackLength+=1,this._isInUndoState=!0}},ct.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._isInUndoState||(this._recordUndoState(e),this._getRangeAndRemoveBookmark(e)),this},ct.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},ct.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(e+1c&&h.splitText(c),h===s&&l&&(h=h.splitText(l),d===s&&(d=h,c-=l),s=h,l=0),i=this.createElement(e,t),C(h,i),i.appendChild(h));while(r.nextNode());d.nodeType!==F&&(h.nodeType===F?(d=h,c=h.length):(d=h.parentNode,c=1)),o=this._createRange(s,l,d,c)}return o},ct._removeFormat=function(e,t,n,o){this._saveRangeToBookmark(n);var i,r=this._doc;n.collapsed&&(he?(i=r.createTextNode(Y),this._didAddZWS()):i=r.createTextNode(""),Be(n,i));for(var s=n.commonAncestorContainer;a(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!Oe(n,e,!1)){var o,i,r=e.nodeType===F;if(!Oe(n,e,!0))return void("INPUT"===e.nodeName||r&&!e.data||u.push([t,e]));if(r)e===c&&h!==e.length&&u.push([t,e.splitText(h)]),e===d&&l&&(e.splitText(l),u.push([t,e]));else for(o=e.firstChild;o;o=i)i=o.nextSibling,p(o,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(o){return Oe(n,o,!0)&&f(o,e,t)});return o||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1),k(s,n),n},ct.changeFormat=function(e,t,n,o){return n||(n=this.getSelection())?(this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,o)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),fe||this._docWasChanged(),this):this};var vt={DT:"DD",DD:"DT",LI:"LI"},_t=function(e,t,n,o){var i=vt[t.nodeName],r=null,a=b(n,o,t.parentNode,e._root),s=e._config;return i||(i=s.blockTag,r=s.blockAttributes),f(a,i,r)||(t=S(a.ownerDocument,i,r),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(N(a)),a=t),a};ct.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var o=this._root,i=Ue(n,o),r=Pe(n,o);if(i&&r)do if(e(i)||i===r)break;while(i=h(i,o));return t&&(this.setSelection(n),this._updatePath(n,!0),fe||this._docWasChanged()),this},ct.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t);var n,o=this._root;return Me(t,o),Re(t,o),n=xe(t,o,o),Be(t,e.call(this,n)),t.endOffset]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i,Lt=function(e,t,o){for(var i,r,a,s,d,l,c,h=e.ownerDocument,u=new n(e,W,function(e){return!p(e,t,"A")},!1),f=o._config.tagAttributes.a;i=u.nextNode();)for(r=i.data,a=i.parentNode;s=xt.exec(r);)d=s.index,l=d+s[0].length,d&&(c=h.createTextNode(r.slice(0,d)),a.insertBefore(c,i)),c=o.createElement("A",A({href:s[1]?/^(?:ht|f)tps?:/.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[2]},f,!1)),c.textContent=r.slice(d,l),a.insertBefore(c,i),i.data=r=r.slice(l)};ct.insertHTML=function(e,t){var n,o,i,r,a,s,d,l=this._config,c=l.isInsertedHTMLSanitized?l.sanitizeToDOMFragment:null,u=this.getSelection(),f=this._doc;"function"==typeof c?r=c(e,t):(t&&(n=e.indexOf(""),o=e.lastIndexOf(""),n>-1&&o>-1&&(e=e.slice(n+20,o))),i=this.createElement("DIV"),i.innerHTML=e,r=f.createDocumentFragment(),r.appendChild(N(i))),this.saveUndoState(u);try{for(a=this._root,s=r,d={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},Lt(r,r,this),et(r),it(r,a),tt(r),r.normalize();s=h(s,r);)y(s,a);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Ae(u,d.fragment,a),fe||this._docWasChanged(),u.collapse(!1),this._ensureBottomLine()),this.setSelection(u),this._updatePath(u,!0),t&&this.focus()}catch(e){this.didError(e)}return this};var At=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};ct.insertPlainText=function(e,t){var n,o,i,r,a=e.split("\n"),s=this._config,d=s.blockTag,l=s.blockAttributes,c="",h="<"+d;for(n in l)h+=" "+n+'="'+At(l[n])+'"';for(h+=">",o=0,i=a.length;o")+c),a[o]=r;return this.insertHTML(a.join(""),t)};var Ot=function(e,t,n){return function(){return this[e](t,n),this.focus()}};ct.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},ct.bold=Ot("changeFormat",{tag:"B"}),ct.italic=Ot("changeFormat",{tag:"I"}),ct.underline=Ot("changeFormat",{tag:"U"}),ct.strikethrough=Ot("changeFormat",{tag:"S"}),ct.subscript=Ot("changeFormat",{tag:"SUB"},{tag:"SUP"}),ct.superscript=Ot("changeFormat",{tag:"SUP"},{tag:"SUB"}),ct.removeBold=Ot("changeFormat",null,{tag:"B"}),ct.removeItalic=Ot("changeFormat",null,{tag:"I"}),ct.removeUnderline=Ot("changeFormat",null,{tag:"U"}),ct.removeStrikethrough=Ot("changeFormat",null,{tag:"S"}),ct.removeSubscript=Ot("changeFormat",null,{tag:"SUB"}),ct.removeSuperscript=Ot("changeFormat",null,{tag:"SUP"}),ct.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var o=e.indexOf(":")+1;if(o)for(;"/"===e[o];)o+=1;Be(n,this._doc.createTextNode(e.slice(o)))}return t=A(A({href:e},t,!0),this._config.tagAttributes.a,!1),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},ct.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},ct.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()},ct.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()},ct.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{class:"colour",style:"color:"+e}}:null,{tag:"SPAN",attributes:{class:"colour"}}),this.focus()},ct.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{class:"highlight",style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{class:"highlight"}}),this.focus()},ct.setTextAlignment=function(e){return this.forEachBlock(function(t){var n=t.className.split(/\s+/).filter(function(e){return!!e&&!/^align/.test(e)}).join(" ");e?(t.className=n+" align-"+e,t.style.textAlign=e):(t.className=n,t.style.textAlign="")},!0),this.focus()},ct.setTextDirection=function(e){return this.forEachBlock(function(t){e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()},ct.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=this._root,n=e.commonAncestorContainer;n&&!s(n);)n=n.parentNode;if(n||(Me(e,t),n=t),n.nodeType===F)return this;this.saveUndoState(e),Re(e,n);for(var o,i,r=n.ownerDocument,a=e.startContainer,d=e.startOffset,l=e.endContainer,c=e.endOffset,h=r.createDocumentFragment(),u=r.createDocumentFragment(),f=b(l,c,n,t),p=b(a,d,n,t);p!==f;)o=p.nextSibling,h.appendChild(p),p=o;return P(this,h,u),u.normalize(),p=u.firstChild,o=u.lastChild,i=n.childNodes,p?(n.insertBefore(u,f),d=me.call(i,p),c=me.call(i,o)+1):(d=me.call(i,f),c=d),e.setStart(n,d),e.setEnd(n,c),k(n,e),De(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},ct.increaseQuoteLevel=Ot("modifyBlocks",Ct),ct.decreaseQuoteLevel=Ot("modifyBlocks",Nt),ct.makeUnorderedList=Ot("modifyBlocks",Tt),ct.makeOrderedList=Ot("modifyBlocks",bt),ct.removeList=Ot("modifyBlocks",Et),ct.increaseListLevel=Ot("modifyBlocks",kt),ct.decreaseListLevel=Ot("modifyBlocks",Bt),O.isInline=a,O.isBlock=s,O.isContainer=d,O.getBlockWalker=l,O.getPreviousBlock=c,O.getNextBlock=h,O.areAlike=u,O.hasTagAttributes=f,O.getNearest=p,O.isOrContains=g,O.detach=_,O.replaceWith=C,O.empty=N,O.getNodeBefore=Ee,O.getNodeAfter=ke,O.insertNodeInRange=Be,O.extractContentsOfRange=xe,O.deleteContentsOfRange=Le,O.insertTreeFragmentIntoRange=Ae,O.isNodeContainedInRange=Oe,O.moveRangeBoundariesDownTree=De,O.moveRangeBoundariesUpTree=Re,O.getStartBlockOfRange=Ue,O.getEndBlockOfRange=Pe,O.contentWalker=Ie,O.rangeDoesStartAtBlockBoundary=we,O.rangeDoesEndAtBlockBoundary=Fe,O.expandRangeToBlockBoundaries=Me,O.onPaste=dt,O.addLinks=Lt,O.splitBlock=_t,O.startSelectionId=gt,O.endSelectionId=mt,"object"==typeof exports?module.exports=O:"function"==typeof define&&define.amd?define(function(){return O}):(X.Squire=O,top!==X&&"true"===e.documentElement.getAttribute("data-squireinit")&&(X.editor=new O(e),X.onEditorLoad&&(X.onEditorLoad(X.editor),X.onEditorLoad=null)))}(document);