squire-rte
Advanced tools
Comparing version 1.8.14 to 1.9.0
@@ -1,1 +0,2 @@ | ||
!function(e,t){"use strict";var n=1,o=3,i=9,r=11,a=1,s="highlight",d="colour",l="font",c="size",h="",u=e.defaultView,f=navigator.userAgent,p=/Android/.test(f),g=/iP(?:ad|hone|od)/.test(f),m=/Mac OS X/.test(f),v=/Windows NT/.test(f),_=/Gecko\//.test(f),N=/Trident\/[456]\./.test(f),C=!!u.opera,S=/Edge\//.test(f),y=!S&&/WebKit\//.test(f),T=/Trident\/[4567]\./.test(f),E=m?"meta-":"ctrl-",b=N||C,k=N||y,L=N,x="undefined"!=typeof MutationObserver,A="undefined"!=typeof WeakMap,O=/[^ \t\r\n]/,B=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var R={1:1,2:2,3:4,8:128,9:256,11:1024};function D(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}D.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)||(t=t.parentNode);if(!e)return null;if(R[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}},D.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(R[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}},D.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)||(t=t.parentNode);if(!e)return null;if(R[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}};var U=/^(?:#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)$/,P={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1};var I=0,w=1,F=2,M=3,H=A?new WeakMap:null;function W(e){return e.nodeType===n&&!!P[e.nodeName]}function z(e){switch(e.nodeType){case o:return w;case n:case r:if(A&&H.has(e))return H.get(e);break;default:return I}var t;return t=function(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}(e.childNodes,q)?U.test(e.nodeName)?w:F:M,A&&H.set(e,t),t}function q(e){return z(e)===w}function K(e){return z(e)===F}function G(e){return z(e)===M}function Z(e,t){var n=new D(t,a,K);return n.currentNode=e,n}function j(e,t){return(e=Z(e,t).previousNode())!==t?e:null}function $(e,t){return(e=Z(e,t).nextNode())!==t?e:null}function Q(e){return!e.textContent&&!e.querySelector("IMG")}function V(e,t){return!W(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 Y(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 X(e,t,n,o){for(;e&&e!==t;){if(Y(e,n,o))return e;e=e.parentNode}return null}function J(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function ee(e){var t=e.nodeType;return t===n||t===r?e.childNodes.length:e.length||0}function te(e){var t=e.parentNode;return t&&t.removeChild(e),e}function ne(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function oe(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,o=n?n.length:0;o--;)t.appendChild(e.firstChild);return t}function ie(e,n,o,i){var r,a,s,d=e.createElement(n);if(o instanceof Array&&(i=o,o=null),o)for(r in o)o[r]!==t&&d.setAttribute(r,o[r]);if(i)for(a=0,s=i.length;a<s;a+=1)d.appendChild(i[a]);return d}function re(e,t){var n,i,r=t.__squire__,a=e.ownerDocument,s=e;if(e===t&&((i=e.firstChild)&&"BR"!==i.nodeName||(n=r.createDefaultBlock(),i?e.replaceChild(n,i):e.appendChild(n),e=n,n=null)),e.nodeType===o)return s;if(q(e)){for(i=e.firstChild;k&&i&&i.nodeType===o&&!i.data;)e.removeChild(i),i=e.firstChild;i||(k?(n=a.createTextNode(h),r._didAddZWS()):n=a.createTextNode(""))}else if(b){for(;e.nodeType!==o&&!W(e);){if(!(i=e.firstChild)){n=a.createTextNode("");break}e=i}e.nodeType===o?/^ +$/.test(e.data)&&(e.data=""):W(e)&&e.parentNode.insertBefore(a.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=ie(a,"BR");(i=e.lastElementChild)&&!q(i);)e=i;if(n)try{e.appendChild(n)}catch(t){r.didError({name:"Squire: fixCursor – "+t,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return s}function ae(e,t){var n,o,i,r,a=e.childNodes,s=e.ownerDocument,d=null,l=t.__squire__._config;for(n=0,o=a.length;n<o;n+=1)!(r="BR"===(i=a[n]).nodeName)&&q(i)?(d||(d=ie(s,l.blockTag,l.blockAttributes)),d.appendChild(i),n-=1,o-=1):(r||d)&&(d||(d=ie(s,l.blockTag,l.blockAttributes)),re(d,t),r?e.replaceChild(d,i):(e.insertBefore(d,i),n+=1,o+=1),d=null),G(i)&&ae(i,t);return d&&e.appendChild(re(d,t)),e}function se(e,t,i,r){var a,s,d,l=e.nodeType;if(l===o&&e!==i)return se(e.parentNode,e.splitText(t),i,r);if(l===n){if("number"==typeof t&&(t=t<e.childNodes.length?e.childNodes[t]:null),e===i)return t;for(a=e.parentNode,s=e.cloneNode(!1);t;)d=t.nextSibling,s.appendChild(t),t=d;return"OL"===e.nodeName&&X(e,r,"BLOCKQUOTE")&&(s.start=(+e.start||1)+e.childNodes.length-1),re(e,r),re(s,r),(d=e.nextSibling)?a.insertBefore(s,d):a.appendChild(s),se(a,s,i,r)}return t}function de(e,t){if(e.nodeType===o&&(e=e.parentNode),e.nodeType===n){var i={startContainer:t.startContainer,startOffset:t.startOffset,endContainer:t.endContainer,endOffset:t.endOffset};!function e(t,i){for(var r,a,s,d=t.childNodes,l=d.length,c=[];l--;)if(r=d[l],a=l&&d[l-1],l&&q(r)&&V(r,a)&&!P[r.nodeName])i.startContainer===r&&(i.startContainer=a,i.startOffset+=ee(a)),i.endContainer===r&&(i.endContainer=a,i.endOffset+=ee(a)),i.startContainer===t&&(i.startOffset>l?i.startOffset-=1:i.startOffset===l&&(i.startContainer=a,i.startOffset=ee(a))),i.endContainer===t&&(i.endOffset>l?i.endOffset-=1:i.endOffset===l&&(i.endContainer=a,i.endOffset=ee(a))),te(r),r.nodeType===o?a.appendData(r.data):c.push(oe(r));else if(r.nodeType===n){for(s=c.length;s--;)r.appendChild(c.pop());e(r,i)}}(e,i),t.setStart(i.startContainer,i.startOffset),t.setEnd(i.endContainer,i.endOffset)}}function le(e,t,o,i){for(var r,a,s,d=t;(r=d.parentNode)&&r!==i&&r.nodeType===n&&1===r.childNodes.length;)d=r;te(d),s=e.childNodes.length,(a=e.lastChild)&&"BR"===a.nodeName&&(e.removeChild(a),s-=1),e.appendChild(oe(t)),o.setStart(e,s),o.collapse(!0),de(e,o),C&&(a=e.lastChild)&&"BR"===a.nodeName&&e.removeChild(a)}function ce(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&&V(i,e)){if(!G(i)){if(!s)return;(o=ie(a,"DIV")).appendChild(oe(i)),i.appendChild(o)}te(e),n=!G(e),i.appendChild(oe(e)),n&&ae(i,t),r&&ce(r,t)}else s&&(i=ie(a,"DIV"),e.insertBefore(i,r),re(i,t))}var he=function(e,t){for(var o=e.childNodes;t&&e.nodeType===n;)t=(o=(e=o[t-1]).childNodes).length;return e},ue=function(e,t){if(e.nodeType===n){var o=e.childNodes;if(t<o.length)e=o[t];else{for(;e&&!e.nextSibling;)e=e.parentNode;e&&(e=e.nextSibling)}}return e},fe=function(e,t){var n,i,r,a,s=e.startContainer,d=e.startOffset,l=e.endContainer,c=e.endOffset;s.nodeType===o?(i=(n=s.parentNode).childNodes,d===s.length?(d=B.call(i,s)+1,e.collapsed&&(l=n,c=d)):(d&&(a=s.splitText(d),l===s?(c-=d,l=a):l===n&&(c+=1),s=a),d=B.call(i,s)),s=n):i=s.childNodes,d===(r=i.length)?s.appendChild(t):s.insertBefore(t,i[d]),s===l&&(c+=i.length-r),e.setStart(s,d),e.setEnd(l,c)},pe=function(e,t,n){var i=e.startContainer,r=e.startOffset,a=e.endContainer,s=e.endOffset;t||(t=e.commonAncestorContainer),t.nodeType===o&&(t=t.parentNode);for(var d,l,c,h=se(a,s,t,n),u=se(i,r,t,n),f=t.ownerDocument.createDocumentFragment();u!==h;)d=u.nextSibling,f.appendChild(u),u=d;return i=t,r=h?B.call(t.childNodes,h):t.childNodes.length,(l=(c=t.childNodes[r])&&c.previousSibling)&&l.nodeType===o&&c.nodeType===o&&(i=l,r=l.length,l.appendData(c.data),te(c)),e.setStart(i,r),e.collapse(!0),re(t,n),f},ge=function(e,t){var n,o,i=Ce(e,t),r=Se(e,t),a=i!==r;return _e(e),Ne(e,i,r,t),n=pe(e,null,t),_e(e),a&&(r=Se(e,t),i&&r&&i!==r&&le(i,r,e,t)),i&&re(i,t),(o=t.firstChild)&&"BR"!==o.nodeName?e.collapse(!0):(re(t,t),e.selectNodeContents(t.firstChild)),n},me=function(e,t,n){var o,i,r,a,s,d,l,c,h,u,f;for(ae(t,n),o=t;o=$(o,n);)re(o,n);if(e.collapsed||ge(e,n),_e(e),e.collapse(!1),a=X(e.endContainer,n,"BLOCKQUOTE")||n,i=Ce(e,n),c=$(t,t),l=!!i&&Q(i),i&&c&&!l&&!X(c,t,"PRE")&&!X(c,t,"TABLE")){if(Ne(e,i,i,n),e.collapse(!0),s=e.endContainer,d=e.endOffset,Ke(i,n,!1),q(s)&&(s=(h=se(s,d,j(s,n),n)).parentNode,d=B.call(s.childNodes,h)),d!==ee(s))for(r=n.ownerDocument.createDocumentFragment();o=s.childNodes[d];)r.appendChild(o);le(s,c,e,n),d=B.call(s.parentNode.childNodes,s)+1,s=s.parentNode,e.setEnd(s,d)}ee(t)&&(l&&(e.setEndBefore(i),e.collapse(!1),te(i)),Ne(e,a,a,n),u=(h=se(e.endContainer,e.endOffset,a,n))?h.previousSibling:a.lastChild,a.insertBefore(t,h),h?e.setEndBefore(h):e.setEnd(a,ee(a)),i=Se(e,n),_e(e),s=e.endContainer,d=e.endOffset,h&&G(h)&&ce(h,n),(h=u&&u.nextSibling)&&G(h)&&ce(h,n),e.setEnd(s,d)),r&&(le(i,r,f=e.cloneRange(),n),e.setEnd(f.endContainer,f.endOffset)),_e(e)},ve=function(e,t,n){var o=t.ownerDocument.createRange();if(o.selectNode(t),n){var i=e.compareBoundaryPoints(3,o)>-1,r=e.compareBoundaryPoints(1,o)<1;return!i&&!r}var a=e.compareBoundaryPoints(0,o)<1,s=e.compareBoundaryPoints(2,o)>-1;return a&&s},_e=function(e){for(var t,n=e.startContainer,i=e.startOffset,r=e.endContainer,a=e.endOffset,s=!0;n.nodeType!==o&&(t=n.childNodes[i])&&!W(t);)n=t,i=0;if(a)for(;r.nodeType!==o;){if(!(t=r.childNodes[a-1])||W(t)){if(s&&t&&"BR"===t.nodeName){a-=1,s=!1;continue}break}a=ee(r=t)}else for(;r.nodeType!==o&&(t=r.firstChild)&&!W(t);)r=t;e.collapsed?(e.setStart(r,a),e.setEnd(n,i)):(e.setStart(n,i),e.setEnd(r,a))},Ne=function(e,t,n,i){var r,a=e.startContainer,s=e.startOffset,d=e.endContainer,l=e.endOffset,c=!0;for(t||(t=e.commonAncestorContainer),n||(n=t);!s&&a!==t&&a!==i;)r=a.parentNode,s=B.call(r.childNodes,a),a=r;for(;c&&d.nodeType!==o&&d.childNodes[l]&&"BR"===d.childNodes[l].nodeName&&(l+=1,c=!1),d!==n&&d!==i&&l===ee(d);)r=d.parentNode,l=B.call(r.childNodes,d)+1,d=r;e.setStart(a,s),e.setEnd(d,l)},Ce=function(e,t){var n,o=e.startContainer;return(n=q(o)?j(o,t):o!==t&&K(o)?o:$(n=he(o,e.startOffset),t))&&ve(e,n,!0)?n:null},Se=function(e,t){var n,o,i=e.endContainer;if(q(i))n=j(i,t);else if(i!==t&&K(i))n=i;else{if(!(n=ue(i,e.endOffset))||!J(t,n))for(n=t;o=n.lastChild;)n=o;n=j(n,t)}return n&&ve(e,n,!0)?n:null},ye=new D(null,4|a,function(e){return e.nodeType===o?O.test(e.data):"IMG"===e.nodeName}),Te=function(e,t){var n,i=e.startContainer,r=e.startOffset;if(ye.root=null,i.nodeType===o){if(r)return!1;n=i}else if((n=ue(i,r))&&!J(t,n)&&(n=null),!n&&(n=he(i,r)).nodeType===o&&n.length)return!1;return ye.currentNode=n,ye.root=Ce(e,t),!ye.previousNode()},Ee=function(e,t){var n,i=e.endContainer,r=e.endOffset;if(ye.root=null,i.nodeType===o){if((n=i.data.length)&&r<n)return!1;ye.currentNode=i}else ye.currentNode=he(i,r);return ye.root=Se(e,t),!ye.nextNode()},be=function(e,t){var n,o=Ce(e,t),i=Se(e,t);o&&i&&(n=o.parentNode,e.setStart(n,B.call(n.childNodes,o)),n=i.parentNode,e.setEnd(n,B.call(n.childNodes,i)+1))},ke={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},Le=function(e){var t=e.keyCode,n=ke[t],o="",i=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),C&&46===e.which&&(n="."),111<t&&t<124&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(o+="alt-"),e.ctrlKey&&(o+="ctrl-"),e.metaKey&&(o+="meta-")),e.shiftKey&&(o+="shift-"),n=o+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,i):i.collapsed||e.ctrlKey||e.metaKey||1!==(e.key||n).length||(this.saveUndoState(i),ge(i,this._root),this._ensureBottomLine(),this.setSelection(i),this._updatePath(i,!0)))},xe=function(e){return function(t,n){n.preventDefault(),t[e]()}},Ae=function(e,t){return t=t||null,function(n,o){o.preventDefault();var i=n.getSelection();n.hasFormat(e,null,i)?n.changeFormat(null,{tag:e},i):n.changeFormat({tag:e},t,i)}},Oe=function(e,t){try{t||(t=e.getSelection());var n,i=t.startContainer;for(i.nodeType===o&&(i=i.parentNode),n=i;q(n)&&(!n.textContent||n.textContent===h);)n=(i=n).parentNode;i!==n&&(t.setStart(n,B.call(n.childNodes,i)),t.collapse(!0),n.removeChild(i),K(n)||(n=j(n,e._root)),re(n,e._root),_e(t)),i===e._root&&(i=i.firstChild)&&"BR"===i.nodeName&&te(i),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(t){e.didError(t)}},Be={enter:function(e,t,i){var r,a,s,d=e._root;if(t.preventDefault(),e._recordUndoState(i),mt(i.startContainer,d,e),e._removeZWS(),e._getRangeAndRemoveBookmark(i),i.collapsed||ge(i,d),!(r=Ce(i,d))||/^T[HD]$/.test(r.nodeName))return(a=X(i.endContainer,d,"A"))&&(a=a.parentNode,Ne(i,a,a,d),i.collapse(!1)),fe(i,e.createElement("BR")),i.collapse(!1),e.setSelection(i),void e._updatePath(i,!0);if((a=X(r,d,"LI"))&&(r=a),Q(r)){if(X(r,d,"UL")||X(r,d,"OL"))return e.decreaseListLevel(i);if(X(r,d,"BLOCKQUOTE"))return e.modifyBlocks(ut,i)}for(s=ct(e,r,i.startContainer,i.startOffset),at(r),We(r),re(r,d);s.nodeType===n;){var l,c=s.firstChild;if("A"===s.nodeName&&(!s.textContent||s.textContent===h)){ne(s,c=e._doc.createTextNode("")),s=c;break}for(;c&&c.nodeType===o&&!c.data&&(l=c.nextSibling)&&"BR"!==l.nodeName;)te(c),c=l;if(!c||"BR"===c.nodeName||c.nodeType===o&&!C)break;s=c}i=e._createRange(s,0),e.setSelection(i),e._updatePath(i,!0)},backspace:function(e,t,n){var o=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Te(n,o)){t.preventDefault();var i,r=Ce(n,o);if(!r)return;if(ae(r.parentNode,o),i=j(r,o)){if(!i.isContentEditable)return void te(i);for(le(i,r,n,o),r=i.parentNode;r!==o&&!r.nextSibling;)r=r.parentNode;r!==o&&(r=r.nextSibling)&&ce(r,o),e.setSelection(n)}else if(r){if(X(r,o,"UL")||X(r,o,"OL"))return e.decreaseListLevel(n);if(X(r,o,"BLOCKQUOTE"))return e.modifyBlocks(ht,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Oe(e)},0);else t.preventDefault(),ge(n,o),Oe(e,n)},delete:function(e,t,o){var i,r,a,s,d,l,c=e._root;if(e._removeZWS(),e.saveUndoState(o),o.collapsed)if(Ee(o,c)){if(t.preventDefault(),!(i=Ce(o,c)))return;if(ae(i.parentNode,c),r=$(i,c)){if(!r.isContentEditable)return void te(r);for(le(i,r,o,c),r=i.parentNode;r!==c&&!r.nextSibling;)r=r.parentNode;r!==c&&(r=r.nextSibling)&&ce(r,c),e.setSelection(o),e._updatePath(o,!0)}}else{if(a=o.cloneRange(),Ne(o,c,c,c),s=o.endContainer,d=o.endOffset,s.nodeType===n&&(l=s.childNodes[d])&&"IMG"===l.nodeName)return t.preventDefault(),te(l),_e(o),void Oe(e,o);e.setSelection(a),setTimeout(function(){Oe(e)},0)}else t.preventDefault(),ge(o,c),Oe(e,o)},tab:function(e,t,n){var o,i,r=e._root;if(e._removeZWS(),n.collapsed&&Te(n,r))for(o=Ce(n,r);i=o.parentNode;){if("UL"===i.nodeName||"OL"===i.nodeName){t.preventDefault(),e.increaseListLevel(n);break}o=i}},"shift-tab":function(e,t,n){var o,i=e._root;e._removeZWS(),n.collapsed&&Te(n,i)&&(X(o=n.startContainer,i,"UL")||X(o,i,"OL"))&&(t.preventDefault(),e.decreaseListLevel(n))},space:function(e,t,n){var o,i;e._recordUndoState(n),mt(n.startContainer,e._root,e),e._getRangeAndRemoveBookmark(n),i=(o=n.endContainer).parentNode,n.collapsed&&n.endOffset===ee(o)&&("A"===o.nodeName?n.setStartAfter(o):"A"!==i.nodeName||o.nextSibling||n.setStartAfter(i)),n.collapsed||(ge(n,e._root),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};m&&_&&(Be["meta-left"]=function(e,t){t.preventDefault();var n=nt(e);n&&n.modify&&n.modify("move","backward","lineboundary")},Be["meta-right"]=function(e,t){t.preventDefault();var n=nt(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),m||(Be.pageup=function(e){e.moveCursorToStart()},Be.pagedown=function(e){e.moveCursorToEnd()}),Be[E+"b"]=Ae("B"),Be[E+"i"]=Ae("I"),Be[E+"u"]=Ae("U"),Be[E+"shift-7"]=Ae("S"),Be[E+"shift-5"]=Ae("SUB",{tag:"SUP"}),Be[E+"shift-6"]=Ae("SUP",{tag:"SUB"}),Be[E+"shift-8"]=xe("makeUnorderedList"),Be[E+"shift-9"]=xe("makeOrderedList"),Be[E+"["]=xe("decreaseQuoteLevel"),Be[E+"]"]=xe("increaseQuoteLevel"),Be[E+"y"]=xe("redo"),Be[E+"z"]=xe("undo"),Be[E+"shift-z"]=xe("redo");var Re={1:10,2:13,3:16,4:18,5:24,6:32,7:48},De={backgroundColor:{regexp:O,replace:function(e,t){return ie(e,"SPAN",{class:s,style:"background-color:"+t})}},color:{regexp:O,replace:function(e,t){return ie(e,"SPAN",{class:d,style:"color:"+t})}},fontWeight:{regexp:/^bold|^700/i,replace:function(e){return ie(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return ie(e,"I")}},fontFamily:{regexp:O,replace:function(e,t){return ie(e,"SPAN",{class:l,style:"font-family:"+t})}},fontSize:{regexp:O,replace:function(e,t){return ie(e,"SPAN",{class:c,style:"font-size:"+t})}},textDecoration:{regexp:/^underline/i,replace:function(e){return ie(e,"U")}}},Ue=function(e){return function(t,n){var o=ie(t.ownerDocument,e);return n.replaceChild(o,t),o.appendChild(oe(t)),o}},Pe=function(e,t){var n,o,i,r,a,s,d=e.style,l=e.ownerDocument;for(n in De)o=De[n],(i=d[n])&&o.regexp.test(i)&&(s=o.replace(l,i),a||(a=s),r&&r.appendChild(s),r=s,e.style[n]="");return a&&(r.appendChild(oe(e)),"SPAN"===e.nodeName?t.replaceChild(a,e):e.appendChild(a)),r||e},Ie={P:Pe,SPAN:Pe,STRONG:Ue("B"),EM:Ue("I"),INS:Ue("U"),STRIKE:Ue("S"),FONT:function(e,t){var n,o,i,r,a,s=e.face,h=e.size,u=e.color,f=e.ownerDocument;return s&&(a=n=ie(f,"SPAN",{class:l,style:"font-family:"+s}),r=n),h&&(o=ie(f,"SPAN",{class:c,style:"font-size:"+Re[h]+"px"}),a||(a=o),r&&r.appendChild(o),r=o),u&&/^#?([\dA-F]{3}){1,2}$/i.test(u)&&("#"!==u.charAt(0)&&(u="#"+u),i=ie(f,"SPAN",{class:d,style:"color:"+u}),a||(a=i),r&&r.appendChild(i),r=i),a||(a=r=ie(f,"SPAN")),t.replaceChild(a,e),r.appendChild(oe(e)),r},TT:function(e,t){var n=ie(e.ownerDocument,"SPAN",{class:l,style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(oe(e)),n}},we=/^(?: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)|COL(?:GROUP)?|UL)$/,Fe=/^(?:HEAD|META|STYLE)/,Me=new D(null,4|a,function(){return!0}),He=function e(t,i){var r,a,s,d,l,c,h,u,f,p,g,m,v=t.childNodes;for(r=t;q(r);)r=r.parentNode;for(Me.root=r,a=0,s=v.length;a<s;a+=1)if(l=(d=v[a]).nodeName,c=d.nodeType,h=Ie[l],c===n){if(u=d.childNodes.length,h)d=h(d,t);else{if(Fe.test(l)){t.removeChild(d),a-=1,s-=1;continue}if(!we.test(l)&&!q(d)){a-=1,s+=u-1,t.replaceChild(oe(d),d);continue}}u&&e(d,i||"PRE"===l)}else{if(c===o){if(g=d.data,f=!O.test(g.charAt(0)),p=!O.test(g.charAt(g.length-1)),i||!f&&!p)continue;if(f){for(Me.currentNode=d;(m=Me.previousPONode())&&!("IMG"===(l=m.nodeName)||"#text"===l&&O.test(m.data));)if(!q(m)){m=null;break}g=g.replace(/^[ \t\r\n]+/g,m?" ":"")}if(p){for(Me.currentNode=d;(m=Me.nextNode())&&!("IMG"===l||"#text"===l&&O.test(m.data));)if(!q(m)){m=null;break}g=g.replace(/[ \t\r\n]+$/g,m?" ":"")}if(g){d.data=g;continue}}t.removeChild(d),a-=1,s-=1}return t},We=function e(t){for(var i,r=t.childNodes,a=r.length;a--;)(i=r[a]).nodeType!==n||W(i)?i.nodeType!==o||i.data||t.removeChild(i):(e(i),q(i)&&!i.firstChild&&t.removeChild(i))},ze=function(e){return e.nodeType===n?"BR"===e.nodeName:O.test(e.data)},qe=function(e,t){for(var n,o=e.parentNode;q(o);)o=o.parentNode;return(n=new D(o,4|a,ze)).currentNode=e,!!n.nextNode()||t&&!n.previousNode()},Ke=function(e,t,n){var o,i,r,a=e.querySelectorAll("BR"),s=[],d=a.length;for(o=0;o<d;o+=1)s[o]=qe(a[o],n);for(;d--;)(r=(i=a[d]).parentNode)&&(s[d]?q(r)||ae(r,t):te(i))},Ge=function(e,t,n){var o,i,r=t.ownerDocument.body;Ke(t,n,!0),t.setAttribute("style","position:fixed;overflow:hidden;bottom:100%;right:100%;"),r.appendChild(t),o=t.innerHTML,i=t.innerText||t.textContent,v&&(i=i.replace(/\r?\n/g,"\r\n")),e.setData("text/html",o),e.setData("text/plain",i),r.removeChild(t)},Ze=function(e){var t,n,i,r,a,s,d=e.clipboardData,l=this.getSelection(),c=this._root,h=this;if(l.collapsed)e.preventDefault();else{if(this.saveUndoState(l),S||g||!d)setTimeout(function(){try{h._ensureBottomLine()}catch(e){h.didError(e)}},0);else{for(n=(t=Ce(l,c))===Se(l,c)&&t||c,i=ge(l,c),(r=l.commonAncestorContainer).nodeType===o&&(r=r.parentNode);r&&r!==n;)(a=r.cloneNode(!1)).appendChild(i),i=a,r=r.parentNode;(s=this.createElement("div")).appendChild(i),Ge(d,s,c),e.preventDefault()}this.setSelection(l)}},je=function(e){var t,n,i,r,a,s,d=e.clipboardData,l=this.getSelection(),c=this._root;if(!S&&!g&&d){for(n=(t=Ce(l,c))===Se(l,c)&&t||c,l=l.cloneRange(),_e(l),Ne(l,n,n,c),i=l.cloneContents(),(r=l.commonAncestorContainer).nodeType===o&&(r=r.parentNode);r&&r!==n;)(a=r.cloneNode(!1)).appendChild(i),i=a,r=r.parentNode;(s=this.createElement("div")).appendChild(i),Ge(d,s,c),e.preventDefault()}};function $e(e){this.isShiftDown=e.shiftKey}var Qe=function(e){var t,n,o,i,r,a=e.clipboardData,s=a&&a.items,d=this.isShiftDown,l=!1,c=!1,h=null,u=this;if(S&&s){for(t=s.length;t--;)!d&&/^image\/.*/.test(s[t].type)&&(c=!0);c||(s=null)}if(s){for(e.preventDefault(),t=s.length;t--;){if(o=(n=s[t]).type,!d&&"text/html"===o)return void n.getAsString(function(e){u.insertHTML(e,!0)});"text/plain"===o&&(h=n),!d&&/^image\/.*/.test(o)&&(c=!0)}c?(this.fireEvent("dragover",{dataTransfer:a,preventDefault:function(){l=!0}}),l&&this.fireEvent("drop",{dataTransfer:a})):h&&h.getAsString(function(e){u.insertPlainText(e,!0)})}else{if(i=a&&a.types,!S&&i&&(B.call(i,"text/html")>-1||!_&&B.call(i,"text/plain")>-1&&B.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,N=p.endOffset,C=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(C),p.selectNodeContents(C),this.setSelection(p),setTimeout(function(){try{u._awaitingPaste=!1;for(var e,t,n="",o=C;C=o;)o=C.nextSibling,te(C),(e=C.firstChild)&&e===C.lastChild&&"DIV"===e.nodeName&&(C=e),n+=C.innerHTML;t=u._createRange(g,m,v,N),u.setSelection(t),n&&u.insertHTML(n,!0)}catch(e){u.didError(e)}},0)}},Ve=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()};function Ye(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?Ye(e[o],i,n):i);return e}function Xe(e,t){e.nodeType===i&&(e=e.body);var n,o=e.ownerDocument,r=o.defaultView;this._win=r,this._doc=o,this._root=e,this._events={},this._isFocused=!1,this._lastSelection=null,L&&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,x?((n=new MutationObserver(this._docWasChanged.bind(this))).observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._restoreSelection=!1,this.addEventListener("blur",ot),this.addEventListener("mousedown",it),this.addEventListener("touchstart",it),this.addEventListener("focus",rt),this._awaitingPaste=!1,this.addEventListener(N?"beforecut":"cut",Ze),this.addEventListener("copy",je),this.addEventListener("keydown",$e),this.addEventListener("keyup",$e),this.addEventListener(N?"beforepaste":"paste",Qe),this.addEventListener("drop",Ve),this.addEventListener(C?"keypress":"keydown",Le),this._keyHandlers=Object.create(Be),this.setConfig(t),N&&(r.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("")}var Je=Xe.prototype,et=function(e,t,n){var o=n._doc,i=e?DOMPurify.sanitize(e,{ALLOW_UNKNOWN_PROTOCOLS:!0,WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}):null;return i?o.importNode(i,!0):o.createDocumentFragment()};Je.setConfig=function(e){return(e=Ye({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},leafNodeNames:P,undo:{documentSizeThreshold:-1,undoLimit:-1},isInsertedHTMLSanitized:!0,isSetHTMLSanitized:!0,sanitizeToDOMFragment:"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?et:null},e,!0)).blockTag=e.blockTag.toUpperCase(),this._config=e,this},Je.createElement=function(e,t,n){return ie(this._doc,e,t,n)},Je.createDefaultBlock=function(e){var t=this._config;return re(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},Je.didError=function(e){console.log(e)},Je.getDocument=function(){return this._doc},Je.getRoot=function(){return this._root},Je.modifyDocument=function(e){var t=this._mutation;t&&(t.takeRecords().length&&this._docWasChanged(),t.disconnect()),this._ignoreAllChanges=!0,e(),this._ignoreAllChanges=!1,t&&(t.observe(this._root,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._ignoreChange=!1)};var tt={pathChange:1,select:1,input:1,undoStateChange:1};Je.fireEvent=function(e,t){var n,o,i,r=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=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),o=(r=r.slice()).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},Je.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},Je.handleEvent=function(e){this.fireEvent(e.type,e)},Je.addEventListener=function(e,t){var n=this._events[e],o=this._root;return t?(n||(n=this._events[e]=[],tt[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)},Je.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],tt[e]||("selectionchange"===e&&(i=this._doc),i.removeEventListener(e,this,!0)))}return this},Je._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},Je.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")).textContent=h,fe(e,t),o=t.getBoundingClientRect(),(n=t.parentNode).removeChild(t),de(n,e)),o},Je._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return _e(n),this.setSelection(n),this},Je.moveCursorToStart=function(){return this._moveCursorTo(!0)},Je.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var nt=function(e){return e._win.getSelection()||null};function ot(){this._restoreSelection=!0}function it(){this._restoreSelection=!1}function rt(){this._restoreSelection&&this.setSelection(this._lastSelection)}Je.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused)if(p&&!this._restoreSelection)ot.call(this),this.blur(),this.focus();else{g&&this._win.focus();var t=nt(this);t&&(t.removeAllRanges(),t.addRange(e))}else ot.call(this);return this},Je.getSelection=function(){var e,t,n,o,i=nt(this),r=this._root;return this._isFocused&&i&&i.rangeCount&&(t=(e=i.getRangeAt(0).cloneRange()).startContainer,n=e.endContainer,t&&W(t)&&e.setStartBefore(t),n&&W(n)&&e.setEndBefore(n)),e&&J(r,e.commonAncestorContainer)?this._lastSelection=e:J((o=(e=this._lastSelection).commonAncestorContainer).ownerDocument,o)||(e=null),e||(e=this._createRange(r.firstChild,0)),e},Je.getSelectedText=function(){var e=this.getSelection();if(!e||e.collapsed)return"";var t,n=new D(e.commonAncestorContainer,4|a,function(t){return ve(e,t,!0)}),i=e.startContainer,r=e.endContainer,s=n.currentNode=i,d="",l=!1;for(n.filter(s)||(s=n.nextNode());s;)s.nodeType===o?(t=s.data)&&/\S/.test(t)&&(s===r&&(t=t.slice(0,e.endOffset)),s===i&&(t=t.slice(e.startOffset)),d+=t,l=!0):("BR"===s.nodeName||l&&!q(s))&&(d+="\n",l=!1),s=n.nextNode();return d},Je.getPath=function(){return this._path};var at=function(e,t){for(var n,o,i,r=new D(e,4,function(){return!0},!1);o=r.nextNode();)for(;(i=o.data.indexOf(h))>-1&&(!t||o.parentNode!==t);){if(1===o.length){do{(n=o.parentNode).removeChild(o),o=n,r.currentNode=n}while(q(o)&&!ee(o));break}o.deleteData(i,1)}};Je._didAddZWS=function(){this._hasZWS=!0},Je._removeZWS=function(){this._hasZWS&&(at(this._root),this._hasZWS=!1)},Je._updatePath=function(e,t){if(e){var o,i=e.startContainer,r=e.endContainer;(t||i!==this._lastAnchorNode||r!==this._lastFocusNode)&&(this._lastAnchorNode=i,this._lastFocusNode=r,o=i&&r?i===r?function e(t,o){var i,r,a,h,u="";return t&&t!==o&&(u=e(t.parentNode,o),t.nodeType===n&&(u+=(u?">":"")+t.nodeName,(i=t.id)&&(u+="#"+i),(r=t.className.trim())&&((a=r.split(/\s\s*/)).sort(),u+=".",u+=a.join(".")),(h=t.dir)&&(u+="[dir="+h+"]"),a&&(B.call(a,s)>-1&&(u+="[backgroundColor="+t.style.backgroundColor.replace(/ /g,"")+"]"),B.call(a,d)>-1&&(u+="[color="+t.style.color.replace(/ /g,"")+"]"),B.call(a,l)>-1&&(u+="[fontFamily="+t.style.fontFamily.replace(/ /g,"")+"]"),B.call(a,c)>-1&&(u+="[fontSize="+t.style.fontSize+"]")))),u}(r,this._root):"(selection)":"",this._path!==o&&(this._path=o,this.fireEvent("pathChange",{path:o}))),this.fireEvent(e.collapsed?"cursor":"select",{range:e})}},Je._updatePathOnEvent=function(e){var t=this;t._isFocused&&!t._willUpdatePath&&(t._willUpdatePath=!0,setTimeout(function(){t._willUpdatePath=!1,t._updatePath(t.getSelection())},0))},Je.focus=function(){return this._root.focus(),T&&this.fireEvent("focus"),this},Je.blur=function(){return this._root.blur(),T&&this.fireEvent("blur"),this};var st="squire-selection-start",dt="squire-selection-end";Je._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:st,type:"hidden"}),o=this.createElement("INPUT",{id:dt,type:"hidden"});fe(e,n),e.collapse(!1),fe(e,o),2&n.compareDocumentPosition(o)&&(n.id=dt,o.id=st,t=n,n=o,o=t),e.setStartAfter(n),e.setEndBefore(o)},Je._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+st),i=t.querySelector("#"+dt);if(n&&i){var r=n.parentNode,a=i.parentNode,s=B.call(r.childNodes,n),d=B.call(a.childNodes,i);r===a&&(d-=1),te(n),te(i),e||(e=this._doc.createRange()),e.setStart(r,s),e.setEnd(a,d),de(r,e),r!==a&&de(a,e),e.collapsed&&(r=e.startContainer).nodeType===o&&((a=r.childNodes[e.startOffset])&&a.nodeType===o||(a=r.childNodes[e.startOffset-1]),a&&a.nodeType===o&&(e.setStart(a,0),e.collapse(!0)))}return e||null},Je._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(t<16||t>20)||!(t<33||t>45)||this._docWasChanged()},Je._docWasChanged=function(){A&&(H=new WeakMap),this._ignoreAllChanges||(x&&this._ignoreChange?this._ignoreChange=!1:(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")))},Je._recordUndoState=function(e,t){if(!this._isInUndoState||t){var n,o=this._undoIndex,i=this._undoStack,r=this._config.undo,a=r.documentSizeThreshold,s=r.undoLimit;t||(o+=1),o<this._undoStackLength&&(i.length=this._undoStackLength=o),e&&this._saveRangeToBookmark(e),n=this._getHTML(),a>-1&&2*n.length>a&&s>-1&&o>s&&(i.splice(0,o-s),o=s,this._undoStackLength=s),i[o]=n,this._undoIndex=o,this._undoStackLength+=1,this._isInUndoState=!0}},Je.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._recordUndoState(e,this._isInUndoState),this._getRangeAndRemoveBookmark(e),this},Je.undo=function(){if(0!==this._undoIndex||!this._isInUndoState){this._recordUndoState(this.getSelection(),!1),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},Je.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(e+1<t&&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:e+2<t}),this.fireEvent("input")}return this},Je.hasFormat=function(e,t,n){if(e=e.toUpperCase(),t||(t={}),!n&&!(n=this.getSelection()))return!1;!n.collapsed&&n.startContainer.nodeType===o&&n.startOffset===n.startContainer.length&&n.startContainer.nextSibling&&n.setStartBefore(n.startContainer.nextSibling),!n.collapsed&&n.endContainer.nodeType===o&&0===n.endOffset&&n.endContainer.previousSibling&&n.setEndAfter(n.endContainer.previousSibling);var i,r,a=this._root,s=n.commonAncestorContainer;if(X(s,a,e,t))return!0;if(s.nodeType===o)return!1;i=new D(s,4,function(e){return ve(n,e,!0)},!1);for(var d=!1;r=i.nextNode();){if(!X(r,a,e,t))return!1;d=!0}return d},Je.getFontInfo=function(e){var n,i,r,a={color:t,backgroundColor:t,family:t,size:t},s=0;if(!e&&!(e=this.getSelection()))return a;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===o)for(n.nodeType===o&&(n=n.parentNode);s<4&&n;)(i=n.style)&&(!a.color&&(r=i.color)&&(a.color=r,s+=1),!a.backgroundColor&&(r=i.backgroundColor)&&(a.backgroundColor=r,s+=1),!a.family&&(r=i.fontFamily)&&(a.family=r,s+=1),!a.size&&(r=i.fontSize)&&(a.size=r,s+=1)),n=n.parentNode;return a},Je._addFormat=function(e,t,n){var i,r,s,d,l,c,h,u,f=this._root;if(n.collapsed){for(i=re(this.createElement(e,t),f),fe(n,i),n.setStart(i.firstChild,i.firstChild.length),n.collapse(!0),u=i;q(u);)u=u.parentNode;at(u,i)}else{if(r=new D(n.commonAncestorContainer,4|a,function(e){return(e.nodeType===o||"BR"===e.nodeName||"IMG"===e.nodeName)&&ve(n,e,!0)},!1),s=n.startContainer,l=n.startOffset,d=n.endContainer,c=n.endOffset,r.currentNode=s,r.filter(s)||(s=r.nextNode(),l=0),!s)return n;do{!X(h=r.currentNode,f,e,t)&&(h===d&&h.length>c&&h.splitText(c),h===s&&l&&(h=h.splitText(l),d===s&&(d=h,c-=l),s=h,l=0),ne(h,i=this.createElement(e,t)),i.appendChild(h))}while(r.nextNode());d.nodeType!==o&&(h.nodeType===o?(d=h,c=h.length):(d=h.parentNode,c=1)),n=this._createRange(s,l,d,c)}return n},Je._removeFormat=function(e,t,n,i){this._saveRangeToBookmark(n);var r,a=this._doc;n.collapsed&&(k?(r=a.createTextNode(h),this._didAddZWS()):r=a.createTextNode(""),fe(n,r));for(var s=n.commonAncestorContainer;q(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,u=n.endOffset,f=[],p=function(e,t){if(!ve(n,e,!1)){var i,r,a=e.nodeType===o;if(ve(n,e,!0))if(a)e===c&&u!==e.length&&f.push([t,e.splitText(u)]),e===d&&l&&(e.splitText(l),f.push([t,e]));else for(i=e.firstChild;i;i=r)r=i.nextSibling,p(i,t);else"INPUT"===e.nodeName||a&&!e.data||f.push([t,e])}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(o){return ve(n,o,!0)&&Y(o,e,t)});return i||g.forEach(function(e){p(e,e)}),f.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];ne(n,t),t.appendChild(n)}),g.forEach(function(e){ne(e,oe(e))}),this._getRangeAndRemoveBookmark(n),r&&n.collapse(!1),de(s,n),n},Je.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),x||this._docWasChanged(),this):this};var lt={DT:"DD",DD:"DT",LI:"LI",PRE:"PRE"},ct=function(e,t,n,o){var i=lt[t.nodeName],r=null,a=se(n,o,t.parentNode,e._root),s=e._config;return i||(i=s.blockTag,r=s.blockAttributes),Y(a,i,r)||(t=ie(a.ownerDocument,i,r),a.dir&&(t.dir=a.dir),ne(a,t),t.appendChild(oe(a)),a=t),a};Je.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var o=this._root,i=Ce(n,o),r=Se(n,o);if(i&&r)do{if(e(i)||i===r)break}while(i=$(i,o));return t&&(this.setSelection(n),this._updatePath(n,!0),x||this._docWasChanged()),this},Je.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._recordUndoState(t,this._isInUndoState);var n,o=this._root;return be(t,o),Ne(t,o,o,o),n=pe(t,o,o),fe(t,e.call(this,n)),t.endOffset<t.endContainer.childNodes.length&&ce(t.endContainer.childNodes[t.endOffset],o),ce(t.startContainer.childNodes[t.startOffset],o),this._getRangeAndRemoveBookmark(t),this.setSelection(t),this._updatePath(t,!0),x||this._docWasChanged(),this};var ht=function(e){var t=this._root,n=e.querySelectorAll("blockquote");return Array.prototype.filter.call(n,function(e){return!X(e.parentNode,t,"BLOCKQUOTE")}).forEach(function(e){ne(e,oe(e))}),e},ut=function(){return this.createDefaultBlock([this.createElement("INPUT",{id:st,type:"hidden"}),this.createElement("INPUT",{id:dt,type:"hidden"})])},ft=function(e,t,n){for(var o,i,r,a,s=Z(t,e._root),d=e._config.tagAttributes,l=d[n.toLowerCase()],c=d.li;o=s.nextNode();)"LI"===o.parentNode.nodeName&&(o=o.parentNode,s.currentNode=o.lastChild),"LI"!==o.nodeName?(a=e.createElement("LI",c),o.dir&&(a.dir=o.dir),(r=o.previousSibling)&&r.nodeName===n?(r.appendChild(a),te(o)):ne(o,e.createElement(n,l,[a])),a.appendChild(oe(o)),s.currentNode=a):(i=(o=o.parentNode).nodeName)!==n&&/^[OU]L$/.test(i)&&ne(o,e.createElement(n,l,[oe(o)]))},pt=function(e,t){for(var n=e.commonAncestorContainer,o=e.startContainer,i=e.endContainer;n&&n!==t&&!/^[OU]L$/.test(n.nodeName);)n=n.parentNode;if(!n||n===t)return null;for(o===n&&(o=o.childNodes[e.startOffset]),i===n&&(i=i.childNodes[e.endOffset]);o&&o.parentNode!==n;)o=o.parentNode;for(;i&&i.parentNode!==n;)i=i.parentNode;return[n,o,i]};Je.increaseListLevel=function(e){if(!e&&!(e=this.getSelection()))return this.focus();var t=this._root,n=pt(e,t);if(!n)return this.focus();var o=n[0],i=n[1],r=n[2];if(!i||i===o.firstChild)return this.focus();this._recordUndoState(e,this._isInUndoState);var a,s,d=o.nodeName,l=i.previousSibling;l.nodeName!==d&&(a=this._config.tagAttributes[d.toLowerCase()],l=this.createElement(d,a),o.insertBefore(l,i));do{s=i===r?null:i.nextSibling,l.appendChild(i)}while(i=s);return(s=l.nextSibling)&&ce(s,t),this._getRangeAndRemoveBookmark(e),this.setSelection(e),this._updatePath(e,!0),x||this._docWasChanged(),this.focus()},Je.decreaseListLevel=function(e){if(!e&&!(e=this.getSelection()))return this.focus();var t=this._root,n=pt(e,t);if(!n)return this.focus();var o=n[0],i=n[1],r=n[2];i||(i=o.firstChild),r||(r=o.lastChild),this._recordUndoState(e,this._isInUndoState);var a,s=o.parentNode,d=r.nextSibling?se(o,r.nextSibling,s,t):o.nextSibling;if(s!==t&&"LI"===s.nodeName){for(s=s.parentNode;d;)a=d.nextSibling,r.appendChild(d),d=a;d=o.parentNode.nextSibling}var l=!/^[OU]L$/.test(s.nodeName);do{a=i===r?null:i.nextSibling,o.removeChild(i),l&&"LI"===i.nodeName&&(i=this.createDefaultBlock([oe(i)])),s.insertBefore(i,d)}while(i=a);return o.firstChild||te(o),d&&ce(d,t),this._getRangeAndRemoveBookmark(e),this.setSelection(e),this._updatePath(e,!0),x||this._docWasChanged(),this.focus()},Je._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&K(t)||e.appendChild(this.createDefaultBlock())},Je.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},Je._getHTML=function(){return this._root.innerHTML},Je._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do{re(n,t)}while(n=$(n,t));this._ignoreChange=!0},Je.getHTML=function(e){var t,n,o,i,r,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),b)for(n=t=this._root;n=$(n,t);)n.textContent||n.querySelector("BR")||(o=this.createElement("BR"),n.appendChild(o),s.push(o));if(i=this._getHTML().replace(/\u200B/g,""),b)for(r=s.length;r--;)te(s[r]);return a&&this._getRangeAndRemoveBookmark(a),i},Je.setHTML=function(e){var t,n,o,i=this._config,r=i.isSetHTMLSanitized?i.sanitizeToDOMFragment:null,a=this._root;"function"==typeof r?n=r(e,!1,this):((t=this.createElement("DIV")).innerHTML=e,(n=this._doc.createDocumentFragment()).appendChild(oe(t))),He(n),Ke(n,a,!1),ae(n,a);for(var s=n;s=$(s,a);)re(s,a);for(this._ignoreChange=!0;o=a.lastChild;)a.removeChild(o);a.appendChild(n),re(a,a),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var d=this._getRangeAndRemoveBookmark()||this._createRange(a.firstChild,0);return this.saveUndoState(d),this._lastSelection=d,ot.call(this),this._updatePath(d,!0),this},Je.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),q(e))fe(t,e),t.setStartAfter(e);else{for(var n,o=this._root,i=Ce(t,o)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=se(i.parentNode,i.nextSibling,o,o)),n?o.insertBefore(e,n):(o.appendChild(e),n=this.createDefaultBlock(),o.appendChild(n)),t.setStart(n,0),t.setEnd(n,0),_e(t)}return this.focus(),this.setSelection(t),this._updatePath(t),x||this._docWasChanged(),this},Je.insertImage=function(e,t){var n=this.createElement("IMG",Ye({src:e},t,!0));return this.insertElement(n),n};var gt=/\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,mt=function(e,t,n){for(var o,i,r,a,s,d,l,c=e.ownerDocument,h=new D(e,4,function(e){return!X(e,t,"A")},!1),u=n._config.tagAttributes.a;o=h.nextNode();)for(i=o.data,r=o.parentNode;a=gt.exec(i);)d=(s=a.index)+a[0].length,s&&(l=c.createTextNode(i.slice(0,s)),r.insertBefore(l,o)),(l=n.createElement("A",Ye({href:a[1]?/^(?:ht|f)tps?:/.test(a[1])?a[1]:"http://"+a[1]:"mailto:"+a[2]},u,!1))).textContent=i.slice(s,d),r.insertBefore(l,o),o.data=i=i.slice(d)};Je.insertHTML=function(e,t){var n,o,i,r,a,s,d,l=this._config,c=l.isInsertedHTMLSanitized?l.sanitizeToDOMFragment:null,h=this.getSelection(),u=this._doc;"function"==typeof c?r=c(e,t,this):(t&&(n=e.indexOf("\x3c!--StartFragment--\x3e"),o=e.lastIndexOf("\x3c!--EndFragment--\x3e"),n>-1&&o>-1&&(e=e.slice(n+20,o))),/<\/td>((?!<\/tr>)[\s\S])*$/i.test(e)&&(e="<TR>"+e+"</TR>"),/<\/tr>((?!<\/table>)[\s\S])*$/i.test(e)&&(e="<TABLE>"+e+"</TABLE>"),(i=this.createElement("DIV")).innerHTML=e,(r=u.createDocumentFragment()).appendChild(oe(i))),this.saveUndoState(h);try{for(a=this._root,s=r,d={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},mt(r,r,this),He(r),Ke(r,a,!1),We(r),r.normalize();s=$(s,r);)re(s,a);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(me(h,d.fragment,a),x||this._docWasChanged(),h.collapse(!1),this._ensureBottomLine()),this.setSelection(h),this._updatePath(h,!0),t&&this.focus()}catch(e){this.didError(e)}return this};var vt=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};Je.insertPlainText=function(e,t){var n,o,i,r,a=e.split("\n"),s=this._config,d=s.blockTag,l=s.blockAttributes,c="</"+d+">",h="<"+d;for(n in l)h+=" "+n+'="'+vt(l[n])+'"';for(h+=">",o=0,i=a.length;o<i;o+=1)r=a[o],r=vt(r).replace(/ (?= )/g," "),a[o]=h+(r||"<BR>")+c;return this.insertHTML(a.join(""),t)};var _t=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Je.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},Je.bold=_t("changeFormat",{tag:"B"}),Je.italic=_t("changeFormat",{tag:"I"}),Je.underline=_t("changeFormat",{tag:"U"}),Je.strikethrough=_t("changeFormat",{tag:"S"}),Je.subscript=_t("changeFormat",{tag:"SUB"},{tag:"SUP"}),Je.superscript=_t("changeFormat",{tag:"SUP"},{tag:"SUB"}),Je.removeBold=_t("changeFormat",null,{tag:"B"}),Je.removeItalic=_t("changeFormat",null,{tag:"I"}),Je.removeUnderline=_t("changeFormat",null,{tag:"U"}),Je.removeStrikethrough=_t("changeFormat",null,{tag:"S"}),Je.removeSubscript=_t("changeFormat",null,{tag:"SUB"}),Je.removeSuperscript=_t("changeFormat",null,{tag:"SUP"}),Je.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var o=e.indexOf(":")+1;if(o)for(;"/"===e[o];)o+=1;fe(n,this._doc.createTextNode(e.slice(o)))}return t=Ye(Ye({href:e},t,!0),this._config.tagAttributes.a,!1),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},Je.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Je.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{class:l,style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{class:l}}),this.focus()},Je.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{class:c,style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{class:c}}),this.focus()},Je.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{class:d,style:"color:"+e}}:null,{tag:"SPAN",attributes:{class:d}}),this.focus()},Je.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{class:s,style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{class:s}}),this.focus()},Je.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()},Je.setTextDirection=function(e){return this.forEachBlock(function(t){e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()},Je.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=this._root,n=e.commonAncestorContainer;n&&!K(n);)n=n.parentNode;if(n||(be(e,t),n=t),n.nodeType===o)return this;this.saveUndoState(e),Ne(e,n,n,t);for(var i,r,a=n.ownerDocument,s=e.startContainer,d=e.startOffset,l=e.endContainer,c=e.endOffset,h=a.createDocumentFragment(),u=a.createDocumentFragment(),f=se(l,c,n,t),p=se(s,d,n,t);p!==f;)i=p.nextSibling,h.appendChild(p),p=i;return function e(t,n,i){var r,a;for(r=n.firstChild;r;r=a){if(a=r.nextSibling,q(r)){if(r.nodeType===o||"BR"===r.nodeName||"IMG"===r.nodeName){i.appendChild(r);continue}}else if(K(r)){i.appendChild(t.createDefaultBlock([e(t,r,t._doc.createDocumentFragment())]));continue}e(t,r,i)}return i}(this,h,u),u.normalize(),p=u.firstChild,i=u.lastChild,r=n.childNodes,p?(n.insertBefore(u,f),d=B.call(r,p),c=B.call(r,i)+1):c=d=B.call(r,f),e.setStart(n,d),e.setEnd(n,c),de(n,e),_e(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},Je.increaseQuoteLevel=_t("modifyBlocks",function(e){return this.createElement("BLOCKQUOTE",this._config.tagAttributes.blockquote,[e])}),Je.decreaseQuoteLevel=_t("modifyBlocks",ht),Je.makeUnorderedList=_t("modifyBlocks",function(e){return ft(this,e,"UL"),e}),Je.makeOrderedList=_t("modifyBlocks",function(e){return ft(this,e,"OL"),e}),Je.removeList=_t("modifyBlocks",function(e){var t,n,o,i,r,a=e.querySelectorAll("UL, OL"),s=e.querySelectorAll("LI"),d=this._root;for(t=0,n=a.length;t<n;t+=1)ae(i=oe(o=a[t]),d),ne(o,i);for(t=0,n=s.length;t<n;t+=1)K(r=s[t])?ne(r,this.createDefaultBlock([oe(r)])):(ae(r,d),ne(r,oe(r)));return e}),Xe.isInline=q,Xe.isBlock=K,Xe.isContainer=G,Xe.getBlockWalker=Z,Xe.getPreviousBlock=j,Xe.getNextBlock=$,Xe.areAlike=V,Xe.hasTagAttributes=Y,Xe.getNearest=X,Xe.isOrContains=J,Xe.detach=te,Xe.replaceWith=ne,Xe.empty=oe,Xe.getNodeBefore=he,Xe.getNodeAfter=ue,Xe.insertNodeInRange=fe,Xe.extractContentsOfRange=pe,Xe.deleteContentsOfRange=ge,Xe.insertTreeFragmentIntoRange=me,Xe.isNodeContainedInRange=ve,Xe.moveRangeBoundariesDownTree=_e,Xe.moveRangeBoundariesUpTree=Ne,Xe.getStartBlockOfRange=Ce,Xe.getEndBlockOfRange=Se,Xe.contentWalker=ye,Xe.rangeDoesStartAtBlockBoundary=Te,Xe.rangeDoesEndAtBlockBoundary=Ee,Xe.expandRangeToBlockBoundaries=be,Xe.onPaste=Qe,Xe.addLinks=mt,Xe.splitBlock=ct,Xe.startSelectionId=st,Xe.endSelectionId=dt,"object"==typeof exports?module.exports=Xe:"function"==typeof define&&define.amd?define(function(){return Xe}):(u.Squire=Xe,top!==u&&"true"===e.documentElement.getAttribute("data-squireinit")&&(u.editor=new Xe(e),u.onEditorLoad&&(u.onEditorLoad(u.editor),u.onEditorLoad=null)))}(document); | ||
!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n||ce}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&&!!ue[e.nodeName]}function r(e){switch(e.nodeType){case F:return pe;case w:case H:if(ae&&ve.has(e))return ve.get(e);break;default:return fe}var t;return t=o(e.childNodes,a)?he.test(e.nodeName)?pe:ge:me,ae&&ve.set(e,t),t}function a(e){return r(e)===pe}function s(e){return r(e)===ge}function d(e){return r(e)===me}function l(e,t){var o=new n(t,W,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){return!e.textContent&&!e.querySelector("IMG")}function f(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 p(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 g(e,t,n,o){for(;e&&e!==t;){if(p(e,n,o))return e;e=e.parentNode}return null}function m(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function v(e,t,n){var o,i,r,a,s,d="";return e&&e!==t&&(d=v(e.parentNode,t,n),e.nodeType===w&&(d+=(d?">":"")+e.nodeName,(o=e.id)&&(d+="#"+o),(i=e.className.trim())&&(r=i.split(/\s\s*/),r.sort(),d+=".",d+=r.join(".")),(a=e.dir)&&(d+="[dir="+a+"]"),r&&(s=n.classNames,de.call(r,s.highlight)>-1&&(d+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),de.call(r,s.colour)>-1&&(d+="[color="+e.style.color.replace(/ /g,"")+"]"),de.call(r,s.fontFamily)>-1&&(d+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),de.call(r,s.fontSize)>-1&&(d+="[fontSize="+e.style.fontSize+"]")))),d}function C(e){var t=e.nodeType;return t===w||t===H?e.childNodes.length:e.length||0}function _(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,o=n?n.length:0;o--;)t.appendChild(e.firstChild);return t}function y(e,n,o,i){var r,a,s,d=e.createElement(n);if(o instanceof Array&&(i=o,o=null),o)for(r in o)o[r]!==t&&d.setAttribute(r,o[r]);if(i)for(a=0,s=i.length;a<s;a+=1)d.appendChild(i[a]);return d}function T(e,t){var n,o,r=t.__squire__,s=e.ownerDocument,d=e;if(e===t&&((o=e.firstChild)&&"BR"!==o.nodeName||(n=r.createDefaultBlock(),o?e.replaceChild(n,o):e.appendChild(n),e=n,n=null)),e.nodeType===F)return d;if(a(e)){for(o=e.firstChild;oe&&o&&o.nodeType===F&&!o.data;)e.removeChild(o),o=e.firstChild;o||(oe?(n=s.createTextNode(z),r._didAddZWS()):n=s.createTextNode(""))}else if(ne){for(;e.nodeType!==F&&!i(e);){if(!(o=e.firstChild)){n=s.createTextNode("");break}e=o}e.nodeType===F?/^ +$/.test(e.data)&&(e.data=""):i(e)&&e.parentNode.insertBefore(s.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=y(s,"BR");(o=e.lastElementChild)&&!a(o);)e=o;if(n)try{e.appendChild(n)}catch(t){r.didError({name:"Squire: fixCursor – "+t,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return d}function E(e,t){var n,o,i,r,s=e.childNodes,l=e.ownerDocument,c=null,h=t.__squire__._config;for(n=0,o=s.length;n<o;n+=1)i=s[n],r="BR"===i.nodeName,!r&&a(i)?(c||(c=y(l,h.blockTag,h.blockAttributes)),c.appendChild(i),n-=1,o-=1):(r||c)&&(c||(c=y(l,h.blockTag,h.blockAttributes)),T(c,t),r?e.replaceChild(c,i):(e.insertBefore(c,i),n+=1,o+=1),c=null),d(i)&&E(i,t);return c&&e.appendChild(T(c,t)),e}function b(e,t,n,o){var i,r,a,s=e.nodeType;if(s===F&&e!==n)return b(e.parentNode,e.splitText(t),n,o);if(s===w){if("number"==typeof t&&(t=t<e.childNodes.length?e.childNodes[t]:null),e===n)return t;for(i=e.parentNode,r=e.cloneNode(!1);t;)a=t.nextSibling,r.appendChild(t),t=a;return"OL"===e.nodeName&&g(e,o,"BLOCKQUOTE")&&(r.start=(+e.start||1)+e.childNodes.length-1),T(e,o),T(r,o),(a=e.nextSibling)?i.insertBefore(r,a):i.appendChild(r),b(i,r,n,o)}return t}function x(e,t){for(var n,o,i,r=e.childNodes,s=r.length,d=[];s--;)if(n=r[s],o=s&&r[s-1],s&&a(n)&&f(n,o)&&!ue[n.nodeName])t.startContainer===n&&(t.startContainer=o,t.startOffset+=C(o)),t.endContainer===n&&(t.endContainer=o,t.endOffset+=C(o)),t.startContainer===e&&(t.startOffset>s?t.startOffset-=1:t.startOffset===s&&(t.startContainer=o,t.startOffset=C(o))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=o,t.endOffset=C(o))),_(n),n.nodeType===F?o.appendData(n.data):d.push(S(n));else if(n.nodeType===w){for(i=d.length;i--;)n.appendChild(d.pop());x(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};x(e,n),t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)}}function A(e,t,n,o){for(var i,r,a,s=t;(i=s.parentNode)&&i!==o&&i.nodeType===w&&1===i.childNodes.length;)s=i;_(s),a=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),a-=1),e.appendChild(S(t)),n.setStart(e,a),n.collapse(!0),k(e,n),Y&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function L(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&&f(i,e)){if(!d(i)){if(!s)return;o=y(a,"DIV"),o.appendChild(S(i)),i.appendChild(o)}_(e),n=!d(e),i.appendChild(S(e)),n&&E(i,t),r&&L(r,t)}else s&&(i=y(a,"DIV"),e.insertBefore(i,r),T(i,t))}function B(e){this.isShiftDown=e.shiftKey}function O(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?O(e[o],i,n):i);return e}function R(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,ie&&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,re?(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",P),this.addEventListener("touchstart",P),this.addEventListener("focus",U),this._awaitingPaste=!1,this.addEventListener(V?"beforecut":"cut",Je),this.addEventListener("copy",et),this.addEventListener("keydown",B),this.addEventListener("keyup",B),this.addEventListener(V?"beforepaste":"paste",tt),this.addEventListener("drop",nt),this.addEventListener(Y?"keypress":"keydown",Pe),this._keyHandlers=Object.create(Fe),this.setConfig(t),V&&(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 P(){this._restoreSelection=!1}function U(){this._restoreSelection&&this.setSelection(this._lastSelection)}function I(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([I(e,o,e._doc.createDocumentFragment())]));continue}I(e,o,n)}return n}var w=1,F=3,M=9,H=11,W=1,z="",q=e.defaultView,K=navigator.userAgent,G=/Android/.test(K),Z=/iP(?:ad|hone|od)/.test(K),j=/Mac OS X/.test(K),$=/Windows NT/.test(K),Q=/Gecko\//.test(K),V=/Trident\/[456]\./.test(K),Y=!!q.opera,X=/Edge\//.test(K),J=!X&&/WebKit\//.test(K),ee=/Trident\/[4567]\./.test(K),te=j?"meta-":"ctrl-",ne=V||Y,oe=V||J,ie=V,re="undefined"!=typeof MutationObserver,ae="undefined"!=typeof WeakMap,se=/[^ \t\r\n]/,de=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var le={1:1,2:2,3:4,8:128,9:256,11:1024},ce=function(){return!0};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)||(t=t.parentNode);if(!e)return null;if(le[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(le[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)||(t=t.parentNode);if(!e)return null;if(le[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}};var he=/^(?:#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)$/,ue={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},fe=0,pe=1,ge=2,me=3,ve=ae?new WeakMap:null,Ce=function(e,t){for(var n=e.childNodes;t&&e.nodeType===w;)e=n[t-1],n=e.childNodes,t=n.length;return e},_e=function(e,t){if(e.nodeType===w){var n=e.childNodes;if(t<n.length)e=n[t];else{for(;e&&!e.nextSibling;)e=e.parentNode;e&&(e=e.nextSibling)}}return e},Ne=function(e,t){var n,o,i,r,a=e.startContainer,s=e.startOffset,d=e.endContainer,l=e.endOffset;a.nodeType===F?(n=a.parentNode,o=n.childNodes,s===a.length?(s=de.call(o,a)+1,e.collapsed&&(d=n,l=s)):(s&&(r=a.splitText(s),d===a?(l-=s,d=r):d===n&&(l+=1),a=r),s=de.call(o,a)),a=n):o=a.childNodes,i=o.length,s===i?a.appendChild(t):a.insertBefore(t,o[s]),a===d&&(l+=o.length-i),e.setStart(a,s),e.setEnd(d,l)},Se=function(e,t,n){var o=e.startContainer,i=e.startOffset,r=e.endContainer,a=e.endOffset;t||(t=e.commonAncestorContainer),t.nodeType===F&&(t=t.parentNode);for(var s,d,l,c,h,u=b(r,a,t,n),f=b(o,i,t,n),p=t.ownerDocument.createDocumentFragment();f!==u;)s=f.nextSibling,p.appendChild(f),f=s;return o=t,i=u?de.call(t.childNodes,u):t.childNodes.length,l=t.childNodes[i],d=l&&l.previousSibling,d&&d.nodeType===F&&l.nodeType===F&&(o=d,i=d.length,c=d.data,h=l.data," "===c.charAt(c.length-1)&&" "===h.charAt(0)&&(h=" "+h.slice(1)),d.appendData(h),_(l)),e.setStart(o,i),e.collapse(!0),T(t,n),p},ye=function(e,t){var n,o,i=ke(e,t),r=Ae(e,t),a=i!==r;return be(e),xe(e,i,r,t),n=Se(e,null,t),be(e),a&&(r=Ae(e,t),i&&r&&i!==r&&A(i,r,e,t)),i&&T(i,t),o=t.firstChild,o&&"BR"!==o.nodeName?e.collapse(!0):(T(t,t),e.selectNodeContents(t.firstChild)),n},Te=function(e,t,n){var o,i,r,s,l,f,p,m,v,N,S;for(E(t,n),o=t;o=h(o,n);)T(o,n);if(e.collapsed||ye(e,n),be(e),e.collapse(!1),s=g(e.endContainer,n,"BLOCKQUOTE")||n,i=ke(e,n),m=h(t,t),p=!!i&&u(i),i&&m&&!p&&!g(m,t,"PRE")&&!g(m,t,"TABLE")){if(xe(e,i,i,n),e.collapse(!0),l=e.endContainer,f=e.endOffset,Ye(i,n,!1),a(l)&&(v=b(l,f,c(l,n),n),l=v.parentNode,f=de.call(l.childNodes,v)),f!==C(l))for(r=n.ownerDocument.createDocumentFragment();o=l.childNodes[f];)r.appendChild(o);A(l,m,e,n),f=de.call(l.parentNode.childNodes,l)+1,l=l.parentNode,e.setEnd(l,f)}C(t)&&(p&&(e.setEndBefore(i),e.collapse(!1),_(i)),xe(e,s,s,n),v=b(e.endContainer,e.endOffset,s,n),N=v?v.previousSibling:s.lastChild,s.insertBefore(t,v),v?e.setEndBefore(v):e.setEnd(s,C(s)),i=Ae(e,n),be(e),l=e.endContainer,f=e.endOffset,v&&d(v)&&L(v,n),v=N&&N.nextSibling,v&&d(v)&&L(v,n),e.setEnd(l,f)),r&&(S=e.cloneRange(),A(i,r,S,n),e.setEnd(S.endContainer,S.endOffset)),be(e)},Ee=function(e,t,n){var o=t.ownerDocument.createRange();if(o.selectNode(t),n){var i=e.compareBoundaryPoints(3,o)>-1,r=e.compareBoundaryPoints(1,o)<1;return!i&&!r}var a=e.compareBoundaryPoints(0,o)<1,s=e.compareBoundaryPoints(2,o)>-1;return a&&s},be=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])&&!i(t);)n=t,o=0;if(a)for(;r.nodeType!==F;){if(!(t=r.childNodes[a-1])||i(t)){if(s&&t&&"BR"===t.nodeName){a-=1,s=!1;continue}break}r=t,a=C(r)}else for(;r.nodeType!==F&&(t=r.firstChild)&&!i(t);)r=t;e.collapsed?(e.setStart(r,a),e.setEnd(n,o)):(e.setStart(n,o),e.setEnd(r,a))},xe=function(e,t,n,o){var i,r=e.startContainer,a=e.startOffset,s=e.endContainer,d=e.endOffset,l=!0;for(t||(t=e.commonAncestorContainer),n||(n=t);!a&&r!==t&&r!==o;)i=r.parentNode,a=de.call(i.childNodes,r),r=i;for(;;){if(l&&s.nodeType!==F&&s.childNodes[d]&&"BR"===s.childNodes[d].nodeName&&(d+=1,l=!1),s===n||s===o||d!==C(s))break;i=s.parentNode,d=de.call(i.childNodes,s)+1,s=i}e.setStart(r,a),e.setEnd(s,d)},ke=function(e,t){var n,o=e.startContainer;return a(o)?n=c(o,t):o!==t&&s(o)?n=o:(n=Ce(o,e.startOffset),n=h(n,t)),n&&Ee(e,n,!0)?n:null},Ae=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=_e(i,e.endOffset))||!m(t,n))for(n=t;o=n.lastChild;)n=o;n=c(n,t)}return n&&Ee(e,n,!0)?n:null},Le=new n(null,4|W,function(e){return e.nodeType===F?se.test(e.data):"IMG"===e.nodeName}),Be=function(e,t){var n,o=e.startContainer,i=e.startOffset;if(Le.root=null,o.nodeType===F){if(i)return!1;n=o}else if(n=_e(o,i),n&&!m(t,n)&&(n=null),!n&&(n=Ce(o,i),n.nodeType===F&&n.length))return!1;return Le.currentNode=n,Le.root=ke(e,t),!Le.previousNode()},Oe=function(e,t){var n,o=e.endContainer,i=e.endOffset;if(Le.root=null,o.nodeType===F){if((n=o.data.length)&&i<n)return!1;Le.currentNode=o}else Le.currentNode=Ce(o,i);return Le.root=Ae(e,t),!Le.nextNode()},Re=function(e,t){var n,o=ke(e,t),i=Ae(e,t);o&&i&&(n=o.parentNode,e.setStart(n,de.call(n.childNodes,o)),n=i.parentNode,e.setEnd(n,de.call(n.childNodes,i)+1))},De={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},Pe=function(e){var t=e.keyCode,n=De[t],o="",i=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),Y&&46===e.which&&(n="."),111<t&&t<124&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(o+="alt-"),e.ctrlKey&&(o+="ctrl-"),e.metaKey&&(o+="meta-")),e.shiftKey&&(o+="shift-"),n=o+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,i):i.collapsed||e.isComposing||e.ctrlKey||e.metaKey||1!==(e.key||n).length||(this.saveUndoState(i),ye(i,this._root),this._ensureBottomLine(),this.setSelection(i),this._updatePath(i,!0)))},Ue=function(e){return function(t,n){n.preventDefault(),t[e]()}},Ie=function(e,t){return t=t||null,function(n,o){o.preventDefault();var i=n.getSelection();n.hasFormat(e,null,i)?n.changeFormat(null,{tag:e},i):n.changeFormat({tag:e},t,i)}},we=function(e,t){try{t||(t=e.getSelection());var n,o=t.startContainer;for(o.nodeType===F&&(o=o.parentNode),n=o;a(n)&&(!n.textContent||n.textContent===z);)o=n,n=o.parentNode;o!==n&&(t.setStart(n,de.call(n.childNodes,o)),t.collapse(!0),n.removeChild(o),s(n)||(n=c(n,e._root)),T(n,e._root),be(t)),o===e._root&&(o=o.firstChild)&&"BR"===o.nodeName&&_(o),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(t){e.didError(t)}},Fe={enter:function(e,t,n){var o,i,r,a,s,d=e._root;if(t.preventDefault(),e._recordUndoState(n),_t(n.startContainer,d,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||ye(n,d),(o=ke(n,d))&&(i=g(o,d,"PRE")))return be(n),r=n.startContainer,a=n.startOffset,r.nodeType!==F&&(r=e._doc.createTextNode(""),i.insertBefore(r,i.firstChild)),t.shiftKey||"\n"!==r.data.charAt(a-1)&&!Be(n,d)||"\n"!==r.data.charAt(a)&&!Oe(n,d)?(r.insertData(a,"\n"),T(i,d),r.length===a+1?n.setStartAfter(r):n.setStart(r,a+1)):(r.deleteData(a&&a-1,a?2:1),s=b(r,a&&a-1,d,d),r=s.previousSibling,r.textContent||_(r),r=e.createDefaultBlock(),s.parentNode.insertBefore(r,s),s.textContent||_(s),n.setStart(r,0)),n.collapse(!0),e.setSelection(n),e._updatePath(n,!0),void e._docWasChanged();if(!o||t.shiftKey||/^T[HD]$/.test(o.nodeName))return i=g(n.endContainer,d,"A"),i&&(i=i.parentNode,xe(n,i,i,d),n.collapse(!1)),Ne(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((i=g(o,d,"LI"))&&(o=i),u(o)){if(g(o,d,"UL")||g(o,d,"OL"))return e.decreaseListLevel(n);if(g(o,d,"BLOCKQUOTE"))return e.modifyBlocks(ft,n)}for(s=ct(e,o,n.startContainer,n.startOffset),st(o),$e(o),T(o,d);s.nodeType===w;){var l,c=s.firstChild;if("A"===s.nodeName&&(!s.textContent||s.textContent===z)){c=e._doc.createTextNode(""),N(s,c),s=c;break}for(;c&&c.nodeType===F&&!c.data&&(l=c.nextSibling)&&"BR"!==l.nodeName;)_(c),c=l;if(!c||"BR"===c.nodeName||c.nodeType===F&&!Y)break;s=c}n=e.createRange(s,0),e.setSelection(n),e._updatePath(n,!0)},"shift-enter":function(e,t,n){return e._keyHandlers.enter(e,t,n)},backspace:function(e,t,n){var o=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Be(n,o)){t.preventDefault();var i,r=ke(n,o);if(!r)return;if(E(r.parentNode,o),i=c(r,o)){if(!i.isContentEditable)return void _(i);for(A(i,r,n,o),r=i.parentNode;r!==o&&!r.nextSibling;)r=r.parentNode;r!==o&&(r=r.nextSibling)&&L(r,o),e.setSelection(n)}else if(r){if(g(r,o,"UL")||g(r,o,"OL"))return e.decreaseListLevel(n);if(g(r,o,"BLOCKQUOTE"))return e.modifyBlocks(ut,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){we(e)},0);else t.preventDefault(),ye(n,o),we(e,n)},delete:function(e,t,n){var o,i,r,a,s,d,l=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Oe(n,l)){if(t.preventDefault(),!(o=ke(n,l)))return;if(E(o.parentNode,l),i=h(o,l)){if(!i.isContentEditable)return void _(i);for(A(o,i,n,l),i=o.parentNode;i!==l&&!i.nextSibling;)i=i.parentNode;i!==l&&(i=i.nextSibling)&&L(i,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(r=n.cloneRange(),xe(n,l,l,l),a=n.endContainer,s=n.endOffset,a.nodeType===w&&(d=a.childNodes[s])&&"IMG"===d.nodeName)return t.preventDefault(),_(d),be(n),void we(e,n);e.setSelection(r),setTimeout(function(){we(e)},0)}else t.preventDefault(),ye(n,l),we(e,n)},tab:function(e,t,n){var o,i,r=e._root;if(e._removeZWS(),n.collapsed&&Be(n,r))for(o=ke(n,r);i=o.parentNode;){if("UL"===i.nodeName||"OL"===i.nodeName){t.preventDefault(),e.increaseListLevel(n);break}o=i}},"shift-tab":function(e,t,n){var o,i=e._root;e._removeZWS(),n.collapsed&&Be(n,i)&&(o=n.startContainer,(g(o,i,"UL")||g(o,i,"OL"))&&(t.preventDefault(),e.decreaseListLevel(n)))},space:function(e,t,n){var o,i=e._root;if(e._recordUndoState(n),_t(n.startContainer,i,e),e._getRangeAndRemoveBookmark(n),o=n.endContainer,n.collapsed&&n.endOffset===C(o))do{if("A"===o.nodeName){n.setStartAfter(o);break}}while(!o.nextSibling&&(o=o.parentNode)&&o!==i);n.collapsed||(ye(n,i),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};j&&Q&&(Fe["meta-left"]=function(e,t){t.preventDefault();var n=at(e);n&&n.modify&&n.modify("move","backward","lineboundary")},Fe["meta-right"]=function(e,t){t.preventDefault();var n=at(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),j||(Fe.pageup=function(e){e.moveCursorToStart()},Fe.pagedown=function(e){e.moveCursorToEnd()}),Fe[te+"b"]=Ie("B"),Fe[te+"i"]=Ie("I"),Fe[te+"u"]=Ie("U"),Fe[te+"shift-7"]=Ie("S"),Fe[te+"shift-5"]=Ie("SUB",{tag:"SUP"}),Fe[te+"shift-6"]=Ie("SUP",{tag:"SUB"}),Fe[te+"shift-8"]=Ue("makeUnorderedList"),Fe[te+"shift-9"]=Ue("makeOrderedList"),Fe[te+"["]=Ue("decreaseQuoteLevel"),Fe[te+"]"]=Ue("increaseQuoteLevel"),Fe[te+"d"]=Ue("toggleCode"),Fe[te+"y"]=Ue("redo"),Fe[te+"z"]=Ue("undo"),Fe[te+"shift-z"]=Ue("redo");var Me={1:10,2:13,3:16,4:18,5:24,6:32,7:48},He={backgroundColor:{regexp:se,replace:function(e,t,n){return y(e,"SPAN",{class:t.highlight,style:"background-color:"+n})}},color:{regexp:se,replace:function(e,t,n){return y(e,"SPAN",{class:t.colour,style:"color:"+n})}},fontWeight:{regexp:/^bold|^700/i,replace:function(e){return y(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return y(e,"I")}},fontFamily:{regexp:se,replace:function(e,t,n){return y(e,"SPAN",{class:t.fontFamily,style:"font-family:"+n})}},fontSize:{regexp:se,replace:function(e,t,n){return y(e,"SPAN",{class:t.fontSize,style:"font-size:"+n})}},textDecoration:{regexp:/^underline/i,replace:function(e){return y(e,"U")}}},We=function(e){return function(t,n){var o=y(t.ownerDocument,e);return n.replaceChild(o,t),o.appendChild(S(t)),o}},ze=function(e,t,n){var o,i,r,a,s,d,l=e.style,c=e.ownerDocument;for(o in He)i=He[o],(r=l[o])&&i.regexp.test(r)&&(d=i.replace(c,n.classNames,r),s||(s=d),a&&a.appendChild(d),a=d,e.style[o]="");return s&&(a.appendChild(S(e)),"SPAN"===e.nodeName?t.replaceChild(s,e):e.appendChild(s)),a||e},qe={P:ze,SPAN:ze,STRONG:We("B"),EM:We("I"),INS:We("U"),STRIKE:We("S"),FONT:function(e,t,n){var o,i,r,a,s,d=e.face,l=e.size,c=e.color,h=e.ownerDocument,u=n.classNames;return d&&(o=y(h,"SPAN",{class:u.fontFamily,style:"font-family:"+d}),s=o,a=o),l&&(i=y(h,"SPAN",{class:u.fontSize,style:"font-size:"+Me[l]+"px"}),s||(s=i),a&&a.appendChild(i),a=i),c&&/^#?([\dA-F]{3}){1,2}$/i.test(c)&&("#"!==c.charAt(0)&&(c="#"+c),r=y(h,"SPAN",{class:u.colour,style:"color:"+c}),s||(s=r),a&&a.appendChild(r),a=r),s||(s=a=y(h,"SPAN")),t.replaceChild(s,e),a.appendChild(S(e)),a},TT:function(e,t,n){var o=y(e.ownerDocument,"SPAN",{class:n.classNames.fontFamily,style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(o,e),o.appendChild(S(e)),o}},Ke=/^(?: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)|COL(?:GROUP)?|UL)$/,Ge=/^(?:HEAD|META|STYLE)/,Ze=new n(null,4|W),je=function e(t,n,o){var i,r,s,d,l,c,h,u,f,p,g,m,v=t.childNodes;for(i=t;a(i);)i=i.parentNode;for(Ze.root=i,r=0,s=v.length;r<s;r+=1)if(d=v[r],l=d.nodeName,c=d.nodeType,h=qe[l],c===w){if(u=d.childNodes.length,h)d=h(d,t,n);else{if(Ge.test(l)){t.removeChild(d),r-=1,s-=1;continue}if(!Ke.test(l)&&!a(d)){r-=1,s+=u-1,t.replaceChild(S(d),d);continue}}u&&e(d,n,o||"PRE"===l)}else{if(c===F){if(g=d.data,f=!se.test(g.charAt(0)),p=!se.test(g.charAt(g.length-1)),o||!f&&!p)continue;if(f){for(Ze.currentNode=d;(m=Ze.previousPONode())&&!("IMG"===(l=m.nodeName)||"#text"===l&&se.test(m.data));)if(!a(m)){m=null;break}g=g.replace(/^[ \t\r\n]+/g,m?" ":"")}if(p){for(Ze.currentNode=d;(m=Ze.nextNode())&&!("IMG"===l||"#text"===l&&se.test(m.data));)if(!a(m)){m=null;break}g=g.replace(/[ \t\r\n]+$/g,m?" ":"")}if(g){d.data=g;continue}}t.removeChild(d),r-=1,s-=1}return t},$e=function e(t){for(var n,o=t.childNodes,r=o.length;r--;)n=o[r],n.nodeType!==w||i(n)?n.nodeType!==F||n.data||t.removeChild(n):(e(n),a(n)&&!n.firstChild&&t.removeChild(n))},Qe=function(e){return e.nodeType===w?"BR"===e.nodeName:se.test(e.data)},Ve=function(e,t){for(var o,i=e.parentNode;a(i);)i=i.parentNode;return o=new n(i,4|W,Qe),o.currentNode=e,!!o.nextNode()||t&&!o.previousNode()},Ye=function(e,t,n){var o,i,r,s=e.querySelectorAll("BR"),d=[],l=s.length;for(o=0;o<l;o+=1)d[o]=Ve(s[o],n);for(;l--;)i=s[l],(r=i.parentNode)&&(d[l]?a(r)||E(r,t):_(i))},Xe=function(e,t,n,o){var i,r,a=t.ownerDocument.body,s=o.willCutCopy;Ye(t,n,!0),t.setAttribute("style","position:fixed;overflow:hidden;bottom:100%;right:100%;"),a.appendChild(t),i=t.innerHTML,r=t.innerText||t.textContent,s&&(i=s(i)),$&&(r=r.replace(/\r?\n/g,"\r\n")),e.setData("text/html",i),e.setData("text/plain",r),a.removeChild(t)},Je=function(e){var t,n,o,i,r,a,s,d=e.clipboardData,l=this.getSelection(),c=this._root,h=this;if(l.collapsed)return void e.preventDefault();if(this.saveUndoState(l),X||Z||!d)setTimeout(function(){try{h._ensureBottomLine()}catch(e){h.didError(e)}},0);else{for(t=ke(l,c),n=Ae(l,c),o=t===n&&t||c,i=ye(l,c),r=l.commonAncestorContainer,r.nodeType===F&&(r=r.parentNode);r&&r!==o;)a=r.cloneNode(!1),a.appendChild(i),i=a,r=r.parentNode;s=this.createElement("div"),s.appendChild(i),Xe(d,s,c,this._config),e.preventDefault()}this.setSelection(l)},et=function(e){var t,n,o,i,r,a,s,d=e.clipboardData,l=this.getSelection(),c=this._root;if(!X&&!Z&&d){for(t=ke(l,c),n=Ae(l,c),o=t===n&&t||c,l=l.cloneRange(),be(l),xe(l,o,o,c),i=l.cloneContents(),r=l.commonAncestorContainer,r.nodeType===F&&(r=r.parentNode);r&&r!==o;)a=r.cloneNode(!1),a.appendChild(i),i=a,r=r.parentNode;s=this.createElement("div"),s.appendChild(i),Xe(d,s,c,this._config),e.preventDefault()}},tt=function(e){var t,n,o,i,r,a=e.clipboardData,s=a&&a.items,d=this.isShiftDown,l=!1,c=!1,h=null,u=this;if(X&&s){for(t=s.length;t--;)!d&&/^image\/.*/.test(s[t].type)&&(c=!0);c||(s=null)}if(s){for(e.preventDefault(),t=s.length;t--;){if(n=s[t],o=n.type,!d&&"text/html"===o)return void n.getAsString(function(e){u.insertHTML(e,!0)});"text/plain"===o&&(h=n),!d&&/^image\/.*/.test(o)&&(c=!0)}return void(c?(this.fireEvent("dragover",{dataTransfer:a,preventDefault:function(){l=!0}}),l&&this.fireEvent("drop",{dataTransfer:a})):h&&h.getAsString(function(e){u.insertPlainText(e,!0)}))}if(i=a&&a.types,!X&&i&&(de.call(i,"text/html")>-1||!Q&&de.call(i,"text/plain")>-1&&de.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)},nt=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()},ot=R.prototype,it=function(e,t,n){var o=n._doc,i=e?DOMPurify.sanitize(e,{ALLOW_UNKNOWN_PROTOCOLS:!0,WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}):null;return i?o.importNode(i,!0):o.createDocumentFragment()};ot.setConfig=function(e){return e=O({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},classNames:{colour:"colour",fontFamily:"font",fontSize:"size",highlight:"highlight"},leafNodeNames:ue,undo:{documentSizeThreshold:-1,undoLimit:-1},isInsertedHTMLSanitized:!0,isSetHTMLSanitized:!0,sanitizeToDOMFragment:"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?it:null,willCutCopy:null},e,!0),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},ot.createElement=function(e,t,n){return y(this._doc,e,t,n)},ot.createDefaultBlock=function(e){var t=this._config;return T(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},ot.didError=function(e){console.log(e)},ot.getDocument=function(){return this._doc},ot.getRoot=function(){return this._root},ot.modifyDocument=function(e){var t=this._mutation;t&&(t.takeRecords().length&&this._docWasChanged(),t.disconnect()),this._ignoreAllChanges=!0,e(),this._ignoreAllChanges=!1,t&&(t.observe(this._root,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._ignoreChange=!1)};var rt={pathChange:1,select:1,input:1,undoStateChange:1};ot.fireEvent=function(e,t){var n,o,i,r=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=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},ot.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},ot.handleEvent=function(e){this.fireEvent(e.type,e)},ot.addEventListener=function(e,t){var n=this._events[e],o=this._root;return t?(n||(n=this._events[e]=[],rt[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)},ot.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],rt[e]||("selectionchange"===e&&(i=this._doc),i.removeEventListener(e,this,!0)))}return this},ot.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},ot.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=z,Ne(e,t),o=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),k(n,e)),o},ot._moveCursorTo=function(e){var t=this._root,n=this.createRange(t,e?0:t.childNodes.length);return be(n),this.setSelection(n),this},ot.moveCursorToStart=function(){return this._moveCursorTo(!0)},ot.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var at=function(e){return e._win.getSelection()||null};ot.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused)if(G&&!this._restoreSelection)D.call(this),this.blur(),this.focus();else{Z&&this._win.focus();var t=at(this);t&&(t.removeAllRanges(),t.addRange(e))}else D.call(this);return this},ot.getSelection=function(){var e,t,n,o,r=at(this),a=this._root;return this._isFocused&&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&&m(a,e.commonAncestorContainer)?this._lastSelection=e:(e=this._lastSelection,o=e.commonAncestorContainer,m(o.ownerDocument,o)||(e=null)),e||(e=this.createRange(a.firstChild,0)),e},ot.getSelectedText=function(){var e=this.getSelection();if(!e||e.collapsed)return"";var t,o=new n(e.commonAncestorContainer,4|W,function(t){return Ee(e,t,!0)}),i=e.startContainer,r=e.endContainer,s=o.currentNode=i,d="",l=!1;for(o.filter(s)||(s=o.nextNode());s;)s.nodeType===F?(t=s.data)&&/\S/.test(t)&&(s===r&&(t=t.slice(0,e.endOffset)),s===i&&(t=t.slice(e.startOffset)),d+=t,l=!0):("BR"===s.nodeName||l&&!a(s))&&(d+="\n",l=!1),s=o.nextNode();return d},ot.getPath=function(){return this._path};var st=function(e,t){for(var o,i,r,s=new n(e,4);i=s.nextNode();)for(;(r=i.data.indexOf(z))>-1&&(!t||i.parentNode!==t);){if(1===i.length){do{o=i.parentNode,o.removeChild(i),i=o,s.currentNode=o}while(a(i)&&!C(i));break}i.deleteData(r,1)}};ot._didAddZWS=function(){this._hasZWS=!0},ot._removeZWS=function(){this._hasZWS&&(st(this._root),this._hasZWS=!1)},ot._updatePath=function(e,t){if(e){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?v(i,this._root,this._config):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),this.fireEvent(e.collapsed?"cursor":"select",{range:e})}},ot._updatePathOnEvent=function(e){var t=this;t._isFocused&&!t._willUpdatePath&&(t._willUpdatePath=!0,setTimeout(function(){t._willUpdatePath=!1,t._updatePath(t.getSelection())},0))},ot.focus=function(){return this._root.focus(),ee&&this.fireEvent("focus"),this},ot.blur=function(){return this._root.blur(),ee&&this.fireEvent("blur"),this};var dt="squire-selection-end" | ||
;ot._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:"squire-selection-start",type:"hidden"}),o=this.createElement("INPUT",{id:dt,type:"hidden"});Ne(e,n),e.collapse(!1),Ne(e,o),2&n.compareDocumentPosition(o)&&(n.id=dt,o.id="squire-selection-start",t=n,n=o,o=t),e.setStartAfter(n),e.setEndBefore(o)},ot._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#squire-selection-start"),o=t.querySelector("#"+dt);if(n&&o){var i=n.parentNode,r=o.parentNode,a=de.call(i.childNodes,n),s=de.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},ot._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(t<16||t>20)||!(t<33||t>45)||this._docWasChanged()},ot._docWasChanged=function(){if(ae&&(ve=new WeakMap),!this._ignoreAllChanges){if(re&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},ot._recordUndoState=function(e,t){if(!this._isInUndoState||t){var n,o=this._undoIndex,i=this._undoStack,r=this._config.undo,a=r.documentSizeThreshold,s=r.undoLimit;t||(o+=1),o<this._undoStackLength&&(i.length=this._undoStackLength=o),e&&this._saveRangeToBookmark(e),n=this._getHTML(),a>-1&&2*n.length>a&&s>-1&&o>s&&(i.splice(0,o-s),o=s,this._undoStackLength=s),i[o]=n,this._undoIndex=o,this._undoStackLength+=1,this._isInUndoState=!0}},ot.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._recordUndoState(e,this._isInUndoState),this._getRangeAndRemoveBookmark(e),this},ot.undo=function(){if(0!==this._undoIndex||!this._isInUndoState){this._recordUndoState(this.getSelection(),!1),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},ot.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(e+1<t&&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:e+2<t}),this.fireEvent("input")}return this},ot.hasFormat=function(e,t,o){if(e=e.toUpperCase(),t||(t={}),!o&&!(o=this.getSelection()))return!1;!o.collapsed&&o.startContainer.nodeType===F&&o.startOffset===o.startContainer.length&&o.startContainer.nextSibling&&o.setStartBefore(o.startContainer.nextSibling),!o.collapsed&&o.endContainer.nodeType===F&&0===o.endOffset&&o.endContainer.previousSibling&&o.setEndAfter(o.endContainer.previousSibling);var i,r,a=this._root,s=o.commonAncestorContainer;if(g(s,a,e,t))return!0;if(s.nodeType===F)return!1;i=new n(s,4,function(e){return Ee(o,e,!0)});for(var d=!1;r=i.nextNode();){if(!g(r,a,e,t))return!1;d=!0}return d},ot.getFontInfo=function(e){var n,o,i,r={color:t,backgroundColor:t,family:t,size:t},a=0;if(!e&&!(e=this.getSelection()))return r;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===F)for(n.nodeType===F&&(n=n.parentNode);a<4&&n;)(o=n.style)&&(!r.color&&(i=o.color)&&(r.color=i,a+=1),!r.backgroundColor&&(i=o.backgroundColor)&&(r.backgroundColor=i,a+=1),!r.family&&(i=o.fontFamily)&&(r.family=i,a+=1),!r.size&&(i=o.fontSize)&&(r.size=i,a+=1)),n=n.parentNode;return r},ot._addFormat=function(e,t,o){var i,r,s,d,l,c,h,u,f=this._root;if(o.collapsed){for(i=T(this.createElement(e,t),f),Ne(o,i),o.setStart(i.firstChild,i.firstChild.length),o.collapse(!0),u=i;a(u);)u=u.parentNode;st(u,i)}else{if(r=new n(o.commonAncestorContainer,4|W,function(e){return(e.nodeType===F||"BR"===e.nodeName||"IMG"===e.nodeName)&&Ee(o,e,!0)}),s=o.startContainer,l=o.startOffset,d=o.endContainer,c=o.endOffset,r.currentNode=s,r.filter(s)||(s=r.nextNode(),l=0),!s)return o;do{h=r.currentNode,!g(h,f,e,t)&&(h===d&&h.length>c&&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),N(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},ot._removeFormat=function(e,t,n,o){this._saveRangeToBookmark(n);var i,r=this._doc;n.collapsed&&(oe?(i=r.createTextNode(z),this._didAddZWS()):i=r.createTextNode(""),Ne(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=[],f=function(e,t){if(!Ee(n,e,!1)){var o,i,r=e.nodeType===F;if(!Ee(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,f(o,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(o){return Ee(n,o,!0)&&p(o,e,t)});return o||g.forEach(function(e){f(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),g.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1),k(s,n),n},ot.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),re||this._docWasChanged(),this):this};var lt={DT:"DD",DD:"DT",LI:"LI",PRE:"PRE"},ct=function(e,t,n,o){var i=lt[t.nodeName],r=null,a=b(n,o,t.parentNode,e._root),s=e._config;return i||(i=s.blockTag,r=s.blockAttributes),p(a,i,r)||(t=y(a.ownerDocument,i,r),a.dir&&(t.dir=a.dir),N(a,t),t.appendChild(S(a)),a=t),a};ot.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var o=this._root,i=ke(n,o),r=Ae(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),re||this._docWasChanged()),this},ot.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._recordUndoState(t,this._isInUndoState);var n,o=this._root;return Re(t,o),xe(t,o,o,o),n=Se(t,o,o),Ne(t,e.call(this,n)),t.endOffset<t.endContainer.childNodes.length&&L(t.endContainer.childNodes[t.endOffset],o),L(t.startContainer.childNodes[t.startOffset],o),this._getRangeAndRemoveBookmark(t),this.setSelection(t),this._updatePath(t,!0),re||this._docWasChanged(),this};var ht=function(e){return this.createElement("BLOCKQUOTE",this._config.tagAttributes.blockquote,[e])},ut=function(e){var t=this._root,n=e.querySelectorAll("blockquote");return Array.prototype.filter.call(n,function(e){return!g(e.parentNode,t,"BLOCKQUOTE")}).forEach(function(e){N(e,S(e))}),e},ft=function(){return this.createDefaultBlock([this.createElement("INPUT",{id:"squire-selection-start",type:"hidden"}),this.createElement("INPUT",{id:dt,type:"hidden"})])},pt=function(e,t,n){for(var o,i,r,a,s=l(t,e._root),d=e._config.tagAttributes,c=d[n.toLowerCase()],h=d.li;o=s.nextNode();)"LI"===o.parentNode.nodeName&&(o=o.parentNode,s.currentNode=o.lastChild),"LI"!==o.nodeName?(a=e.createElement("LI",h),o.dir&&(a.dir=o.dir),(r=o.previousSibling)&&r.nodeName===n?(r.appendChild(a),_(o)):N(o,e.createElement(n,c,[a])),a.appendChild(S(o)),s.currentNode=a):(o=o.parentNode,(i=o.nodeName)!==n&&/^[OU]L$/.test(i)&&N(o,e.createElement(n,c,[S(o)])))},gt=function(e){return pt(this,e,"UL"),e},mt=function(e){return pt(this,e,"OL"),e},vt=function(e){var t,n,o,i,r,a=e.querySelectorAll("UL, OL"),d=e.querySelectorAll("LI"),l=this._root;for(t=0,n=a.length;t<n;t+=1)o=a[t],i=S(o),E(i,l),N(o,i);for(t=0,n=d.length;t<n;t+=1)r=d[t],s(r)?N(r,this.createDefaultBlock([S(r)])):(E(r,l),N(r,S(r)));return e},Ct=function(e,t){for(var n=e.commonAncestorContainer,o=e.startContainer,i=e.endContainer;n&&n!==t&&!/^[OU]L$/.test(n.nodeName);)n=n.parentNode;if(!n||n===t)return null;for(o===n&&(o=o.childNodes[e.startOffset]),i===n&&(i=i.childNodes[e.endOffset]);o&&o.parentNode!==n;)o=o.parentNode;for(;i&&i.parentNode!==n;)i=i.parentNode;return[n,o,i]};ot.increaseListLevel=function(e){if(!e&&!(e=this.getSelection()))return this.focus();var t=this._root,n=Ct(e,t);if(!n)return this.focus();var o=n[0],i=n[1],r=n[2];if(!i||i===o.firstChild)return this.focus();this._recordUndoState(e,this._isInUndoState);var a,s,d=o.nodeName,l=i.previousSibling;l.nodeName!==d&&(a=this._config.tagAttributes[d.toLowerCase()],l=this.createElement(d,a),o.insertBefore(l,i));do{s=i===r?null:i.nextSibling,l.appendChild(i)}while(i=s);return s=l.nextSibling,s&&L(s,t),this._getRangeAndRemoveBookmark(e),this.setSelection(e),this._updatePath(e,!0),re||this._docWasChanged(),this.focus()},ot.decreaseListLevel=function(e){if(!e&&!(e=this.getSelection()))return this.focus();var t=this._root,n=Ct(e,t);if(!n)return this.focus();var o=n[0],i=n[1],r=n[2];i||(i=o.firstChild),r||(r=o.lastChild),this._recordUndoState(e,this._isInUndoState);var a,s=o.parentNode,d=r.nextSibling?b(o,r.nextSibling,s,t):o.nextSibling;if(s!==t&&"LI"===s.nodeName){for(s=s.parentNode;d;)a=d.nextSibling,r.appendChild(d),d=a;d=o.parentNode.nextSibling}var l=!/^[OU]L$/.test(s.nodeName);do{a=i===r?null:i.nextSibling,o.removeChild(i),l&&"LI"===i.nodeName&&(i=this.createDefaultBlock([S(i)])),s.insertBefore(i,d)}while(i=a);return o.firstChild||_(o),d&&L(d,t),this._getRangeAndRemoveBookmark(e),this.setSelection(e),this._updatePath(e,!0),re||this._docWasChanged(),this.focus()},ot._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&s(t)||e.appendChild(this.createDefaultBlock())},ot.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},ot._getHTML=function(){return this._root.innerHTML},ot._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do{T(n,t)}while(n=h(n,t));this._ignoreChange=!0},ot.getHTML=function(e){var t,n,o,i,r,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),ne)for(t=this._root,n=t;n=h(n,t);)n.textContent||n.querySelector("BR")||(o=this.createElement("BR"),n.appendChild(o),s.push(o));if(i=this._getHTML().replace(/\u200B/g,""),ne)for(r=s.length;r--;)_(s[r]);return a&&this._getRangeAndRemoveBookmark(a),i},ot.setHTML=function(e){var t,n,o,i=this._config,r=i.isSetHTMLSanitized?i.sanitizeToDOMFragment:null,a=this._root;"function"==typeof r?n=r(e,!1,this):(t=this.createElement("DIV"),t.innerHTML=e,n=this._doc.createDocumentFragment(),n.appendChild(S(t))),je(n,i),Ye(n,a,!1),E(n,a);for(var s=n;s=h(s,a);)T(s,a);for(this._ignoreChange=!0;o=a.lastChild;)a.removeChild(o);a.appendChild(n),T(a,a),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var d=this._getRangeAndRemoveBookmark()||this.createRange(a.firstChild,0);return this.saveUndoState(d),this._lastSelection=d,D.call(this),this._updatePath(d,!0),this},ot.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),a(e))Ne(t,e),t.setStartAfter(e);else{for(var n,o,i=this._root,r=ke(t,i)||i;r!==i&&!r.nextSibling;)r=r.parentNode;r!==i&&(n=r.parentNode,o=b(n,r.nextSibling,i,i)),o?i.insertBefore(e,o):(i.appendChild(e),o=this.createDefaultBlock(),i.appendChild(o)),t.setStart(o,0),t.setEnd(o,0),be(t)}return this.focus(),this.setSelection(t),this._updatePath(t),re||this._docWasChanged(),this},ot.insertImage=function(e,t){var n=this.createElement("IMG",O({src:e},t,!0));return this.insertElement(n),n},ot.linkRegExp=/\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)(?:\?[^&?\s]+=[^&?\s]+(?:&[^&?\s]+=[^&?\s]+)*)?/i;var _t=function(e,t,o){var i,r,a,s,d,l,c,h=e.ownerDocument,u=new n(e,4,function(e){return!g(e,t,"A")}),f=o.linkRegExp,p=o._config.tagAttributes.a;if(f)for(;i=u.nextNode();)for(r=i.data,a=i.parentNode;s=f.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",O({href:s[1]?/^(?:ht|f)tps?:/i.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[0]},p,!1)),c.textContent=r.slice(d,l),a.insertBefore(c,i),i.data=r=r.slice(l)};ot.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,this):(t&&(n=e.indexOf("\x3c!--StartFragment--\x3e"),o=e.lastIndexOf("\x3c!--EndFragment--\x3e"),n>-1&&o>-1&&(e=e.slice(n+20,o))),/<\/td>((?!<\/tr>)[\s\S])*$/i.test(e)&&(e="<TR>"+e+"</TR>"),/<\/tr>((?!<\/table>)[\s\S])*$/i.test(e)&&(e="<TABLE>"+e+"</TABLE>"),i=this.createElement("DIV"),i.innerHTML=e,r=f.createDocumentFragment(),r.appendChild(S(i))),this.saveUndoState(u);try{for(a=this._root,s=r,d={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},_t(r,r,this),je(r,l),Ye(r,a,!1),$e(r),r.normalize();s=h(s,r);)T(s,a);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Te(u,d.fragment,a),re||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 Nt=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};ot.insertPlainText=function(e,t){var n=this.getSelection();if(n.collapsed&&g(n.startContainer,this._root,"PRE")){var o,i,r=n.startContainer,a=n.startOffset;return r&&r.nodeType===F||(o=this._doc.createTextNode(""),r.insertBefore(o,r.childNodes[a]),r=o,a=0),i={text:e,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},t&&this.fireEvent("willPaste",i),i.defaultPrevented||(e=i.text,r.insertData(a,e),n.setStart(r,a+e.length),n.collapse(!0)),this.setSelection(n),this}var s,d,l,c,h=e.split("\n"),u=this._config,f=u.blockTag,p=u.blockAttributes,m="</"+f+">",v="<"+f;for(s in p)v+=" "+s+'="'+Nt(p[s])+'"';for(v+=">",d=0,l=h.length;d<l;d+=1)c=h[d],c=Nt(c).replace(/ (?= )/g," "),h[d]=v+(c||"<BR>")+m;return this.insertHTML(h.join(""),t)};var St=function(e,t,n){return function(){return this[e](t,n),this.focus()}};ot.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},ot.bold=St("changeFormat",{tag:"B"}),ot.italic=St("changeFormat",{tag:"I"}),ot.underline=St("changeFormat",{tag:"U"}),ot.strikethrough=St("changeFormat",{tag:"S"}),ot.subscript=St("changeFormat",{tag:"SUB"},{tag:"SUP"}),ot.superscript=St("changeFormat",{tag:"SUP"},{tag:"SUB"}),ot.removeBold=St("changeFormat",null,{tag:"B"}),ot.removeItalic=St("changeFormat",null,{tag:"I"}),ot.removeUnderline=St("changeFormat",null,{tag:"U"}),ot.removeStrikethrough=St("changeFormat",null,{tag:"S"}),ot.removeSubscript=St("changeFormat",null,{tag:"SUB"}),ot.removeSuperscript=St("changeFormat",null,{tag:"SUP"}),ot.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var o=e.indexOf(":")+1;if(o)for(;"/"===e[o];)o+=1;Ne(n,this._doc.createTextNode(e.slice(o)))}return t=O(O({href:e},t,!0),this._config.tagAttributes.a,!1),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},ot.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},ot.setFontFace=function(e){var t=this._config.classNames.fontFamily;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.setFontSize=function(e){var t=this._config.classNames.fontSize;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.setTextColour=function(e){var t=this._config.classNames.colour;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"color:"+e}}:null,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.setHighlightColour=function(e){var t=this._config.classNames.highlight;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{class:t}}),this.focus()},ot.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()},ot.setTextDirection=function(e){return this.forEachBlock(function(t){e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()};var yt=function(e){for(var t,o=this._root,i=this._doc,r=i.createDocumentFragment(),a=l(e,o);t=a.nextNode();){var s,d,c=t.querySelectorAll("BR"),h=[],u=c.length;for(s=0;s<u;s+=1)h[s]=Ve(c[s],!1);for(;u--;)d=c[u],h[u]?N(d,i.createTextNode("\n")):_(d);for(c=t.querySelectorAll("CODE"),u=c.length;u--;)_(c[u]);r.childNodes.length&&r.appendChild(i.createTextNode("\n")),r.appendChild(S(t))}for(a=new n(r,4);t=a.nextNode();)t.data=t.data.replace(/ /g," ");return r.normalize(),T(this.createElement("PRE",this._config.tagAttributes.pre,[r]),o)},Tt=function(e){for(var t,o,i,r,a,s,d=this._doc,l=this._root,c=e.querySelectorAll("PRE"),h=c.length;h--;){for(t=c[h],o=new n(t,4);i=o.nextNode();){for(r=i.data,r=r.replace(/ (?= )/g," "),a=d.createDocumentFragment();(s=r.indexOf("\n"))>-1;)a.appendChild(d.createTextNode(r.slice(0,s))),a.appendChild(d.createElement("BR")),r=r.slice(s+1);i.parentNode.insertBefore(a,i),i.data=r}E(t,l),N(t,S(t))}return e};ot.code=function(){var e=this.getSelection();return e.collapsed||d(e.commonAncestorContainer)?this.modifyBlocks(yt,e):this.changeFormat({tag:"CODE",attributes:this._config.tagAttributes.code},null,e),this.focus()},ot.removeCode=function(){var e=this.getSelection();return g(e.commonAncestorContainer,this._root,"PRE")?this.modifyBlocks(Tt,e):this.changeFormat(null,{tag:"CODE"},e),this.focus()},ot.toggleCode=function(){return this.hasFormat("PRE")||this.hasFormat("CODE")?this.removeCode():this.code(),this},ot.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||(Re(e,t),n=t),n.nodeType===F)return this;this.saveUndoState(e),xe(e,n,n,t);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 I(this,h,u),u.normalize(),p=u.firstChild,o=u.lastChild,i=n.childNodes,p?(n.insertBefore(u,f),d=de.call(i,p),c=de.call(i,o)+1):(d=de.call(i,f),c=d),e.setStart(n,d),e.setEnd(n,c),k(n,e),be(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},ot.increaseQuoteLevel=St("modifyBlocks",ht),ot.decreaseQuoteLevel=St("modifyBlocks",ut),ot.makeUnorderedList=St("modifyBlocks",gt),ot.makeOrderedList=St("modifyBlocks",mt),ot.removeList=St("modifyBlocks",vt),R.isInline=a,R.isBlock=s,R.isContainer=d,R.getBlockWalker=l,R.getPreviousBlock=c,R.getNextBlock=h,R.areAlike=f,R.hasTagAttributes=p,R.getNearest=g,R.isOrContains=m,R.detach=_,R.replaceWith=N,R.empty=S,R.getNodeBefore=Ce,R.getNodeAfter=_e,R.insertNodeInRange=Ne,R.extractContentsOfRange=Se,R.deleteContentsOfRange=ye,R.insertTreeFragmentIntoRange=Te,R.isNodeContainedInRange=Ee,R.moveRangeBoundariesDownTree=be,R.moveRangeBoundariesUpTree=xe,R.getStartBlockOfRange=ke,R.getEndBlockOfRange=Ae,R.contentWalker=Le,R.rangeDoesStartAtBlockBoundary=Be,R.rangeDoesEndAtBlockBoundary=Oe,R.expandRangeToBlockBoundaries=Re,R.onPaste=tt,R.addLinks=_t,R.splitBlock=ct,R.startSelectionId="squire-selection-start",R.endSelectionId=dt,"object"==typeof exports?module.exports=R:"function"==typeof define&&define.amd?define(function(){return R}):(q.Squire=R,top!==q&&"true"===e.documentElement.getAttribute("data-squireinit")&&(q.editor=new R(e),q.onEditorLoad&&(q.onEditorLoad(q.editor),q.onEditorLoad=null)))}(document); |
{ | ||
"name": "squire-rte", | ||
"version": "1.8.14", | ||
"version": "1.9.0", | ||
"description": "Squire is an HTML5 rich text editor, which provides powerful cross-browser normalisation, whilst being supremely lightweight and flexible.", | ||
@@ -5,0 +5,0 @@ "main": "build/squire.js", |
Squire | ||
====== | ||
Squire is an HTML5 rich text editor, which provides powerful cross-browser normalisation, whilst being supremely lightweight and flexible. It is built for the present and the future, and as such does not support truly ancient browsers. It should work fine back to around Opera 12, Firefox 3.5, Safari 5, Chrome 9 and IE9. | ||
Squire is an HTML5 rich text editor, which provides powerful cross-browser normalisation in a flexible lightweight package (only 16.5KB of JS after minification and gzip, with no dependencies!). | ||
An example UI integration can be tried at http://neilj.github.io/Squire/. | ||
It was designed to handle email composition for the [FastMail](https://www.fastmail.com) web app. The most important consequence of this (and where Squire differs from most other modern rich text editors) is that it must handle arbitrary HTML, because it may be used to forward or quote emails from third-parties and must be able to preserve their HTML without breaking the formatting. This means that it can't use a more structured (but limited) internal data model (as most other modern HTML editors do) and the HTML remains the source-of-truth. The other consequence is excellent handling of multiple levels of blockquotes. | ||
Unlike other HTML5 rich text editors, Squire was written as a component for writing documents (emails, essays, etc.), not doing wysiwyg websites. If you are looking for support for inserting form controls or flash components or the like, you'll need to look elsewhere. However for many purposes, Squire may be just what you need, providing the power without the bloat. The key features are: | ||
Squire was designed to be integrated with your own UI framework, and so does not provide its own UI toolbar, widgets or overlays. Instead, you get a component you can insert in place of a `<textarea>` and manipulate programatically, allowing you to integrate seamlessly with the rest of your application and lose the bloat of having two UI toolkits loaded. | ||
### Lightweight ### | ||
Squire supports all reasonably recent, and even moderately old, browsers (even IE11, although this is not tested much these days). | ||
* Only 11.5KB of JS after minification and gzip (35KB before gzip). | ||
* Does not include its own XHR wrapper, widget library or lightbox overlays. | ||
* No dependencies. | ||
* No UI for a toolbar is supplied, allowing you to integrate seamlessly with the rest of your application and lose the bloat of having two UI toolkits loaded. Instead, you get a component you can insert in place of a `<textarea>` and manipulate programatically. | ||
In addition to its use at [FastMail](https://www.fastmail.com), is is also currently used in production at [ProtonMail](https://protonmail.com/), [Zoho Mail](https://www.zoho.com/mail/) and [Superhuman](https://superhuman.com/), as well as other non-mail apps (drop me a line if you're using Squire elsewhere, I'm always interested to hear about it!). | ||
### Powerful ### | ||
An example UI integration can be tried at http://neilj.github.io/Squire/. Please note though, this is an out-of-date version of Squire and a slightly buggy implementation written by an intern many years ago. For a demo of the latest version with a production-level UI integration, [sign up for a free FastMail trial](https://www.fastmail.com/signup/) :). There's also a very bare-bones integration in the repo; just clone it and open `Demo.html`. If you are reporting a bug, please report the steps to reproduce using `Demo.html`, to make sure it's not a bug in your integration. | ||
Squire provides an engine that handles the heavy work for you, making it easy to add extra features. With the `changeFormat` method you can easily add or remove any inline formatting you wish. And the `modifyBlocks` method can be used to make complicated block-level changes in a relatively easy manner. | ||
If you need more commands than in the simple API, I suggest you check out the source code (it's not very long), and see how a lot of the other API methods are implemented in terms of these two methods. | ||
The general philosophy of Squire is to allow the browser to do as much as it can (which unfortunately is not very much), but take control anywhere it deviates from what is required, or there are significant cross-browser differences. As such, the [`document.execCommand`](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) method is not used at all; instead all formatting is done via custom functions, and certain keys, such as 'enter' and 'backspace' are handled by the editor. | ||
Installation and usage | ||
@@ -64,2 +55,4 @@ ---------------------- | ||
Squire provides an engine that handles the heavy work for you, making it easy to add extra features. With the `changeFormat` method you can easily add or remove any inline formatting you wish. And the `modifyBlocks` method can be used to make complicated block-level changes in a relatively easy manner. | ||
If you load the library into a top-level document (rather than an iframe), or load it in an iframe without the `data-squireinit="true"` attribute on its `<html>` element, it will not turn the page into an editable document, but will instead add a constructor named `Squire` to the global scope. | ||
@@ -71,2 +64,6 @@ | ||
If you need more commands than in the simple API, I suggest you check out the source code (it's not very long), and see how a lot of the other API methods are implemented in terms of these two methods. | ||
The general philosophy of Squire is to allow the browser to do as much as it can (which unfortunately is not very much), but take control anywhere it deviates from what is required, or there are significant cross-browser differences. As such, the [`document.execCommand`](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) method is not used at all; instead all formatting is done via custom functions, and certain keys, such as 'enter' and 'backspace' are handled by the editor. | ||
### Setting the default block style | ||
@@ -114,3 +111,3 @@ | ||
* **undoStateChange**: The availability of undo and/or redo has changed. The event object has two boolean properties, `canUndo` and `canRedo` to let you know the new state. | ||
* **willPaste**: The user is pasting content into the document. The content that will be inserted is available as the `fragment` property on the event object. You can modify this fragment in your event handler to change what will be pasted. You can also call the `preventDefault` on the event object to cancel the paste operation. | ||
* **willPaste**: The user is pasting content into the document. The content that will be inserted is available as either the `fragment` property on the event object, or the `text` property for plain text being inserted into a `<pre>`. You can modify this text/fragment in your event handler to change what will be pasted. You can also call the `preventDefault` on the event object to cancel the paste operation. | ||
@@ -216,2 +213,11 @@ The method takes two arguments: | ||
### createRange | ||
Creates a range in the document belonging to the editor. Takes 4 arguments, matching the [W3C Range properties](https://developer.mozilla.org/en-US/docs/Web/API/Range) they set: | ||
* **startContainer** | ||
* **startOffset** | ||
* **endContainer** (optional; if not collapsed) | ||
* **endOffset** (optional; if not collapsed) | ||
### getCursorPosition | ||
@@ -458,2 +464,20 @@ | ||
### code | ||
If no selection, or selection across blocks, converts the block to a `<pre>` to format the text as fixed-width. If a selection within a single block is present, wraps that in `<code>` tags for inline formatting instead. | ||
Returns self (the Squire instance). | ||
### removeCode | ||
If inside a `<pre>`, converts that to the default block type instead. Otherwise, removes any `<code>` tags. | ||
Returns self (the Squire instance). | ||
### toggleCode | ||
If inside a `<pre>` or `<code>`, calls `removeCode()`, otherwise callse `code()`. | ||
Returns self (the Squire instance). | ||
### removeAllFormatting | ||
@@ -479,1 +503,7 @@ | ||
This is useful when the document needs to be changed programmatically, but those changes should not raise input events or modify the undo state. | ||
### linkRegExp | ||
This is the regular expression used to automatically mark up links when inserting HTML or after pressing space. You can change it if you want to use a custom regular expression for detecting links, or set to `null` to turn off link detection. | ||
@@ -364,2 +364,61 @@ /*global expect, describe, afterEach, beforeEach, it */ | ||
}); | ||
var LINK_MAP = { | ||
"dewdw@fre.fr": "mailto:dewdw@fre.fr", | ||
"dew@free.fr?dew=dew": "mailto:dew@free.fr?dew=dew", | ||
"dew@free.fr?subject=dew": "mailto:dew@free.fr?subject=dew", | ||
"test@example.com?subject=foo&body=bar": "mailto:test@example.com?subject=foo&body=bar", | ||
"dew@fre.fr dewdwe @dew": "mailto:dew@fre.fr", | ||
"http://free.fr": "http://free.fr", | ||
"http://google.com": "http://google.com", | ||
"https://google.com": "https://google.com", | ||
"https://www.google.com": "https://www.google.com", | ||
"https://www.google.com/": "https://www.google.com/", | ||
"https://google.com/?": "https://google.com/", | ||
"https://google.com?": "https://google.com", | ||
"https://google.com?a": "https://google.com/?a", | ||
"https://google.com?a=": "https://google.com/?a=", | ||
"https://google.com?a=b": "https://google.com/?a=b", | ||
"https://google.com?a=b?": "https://google.com/?a=b", | ||
"https://google.com?a=b&": "https://google.com/?a=b&", | ||
"https://google.com?a=b&c": "https://google.com/?a=b&c", | ||
"https://google.com?a=b&c=": "https://google.com/?a=b&c=", | ||
"https://google.com?a=b&c=d": "https://google.com/?a=b&c=", | ||
"https://google.com?a=b&c=d?": "https://google.com/?a=b&c=d", | ||
"https://google.com?a=b&c=d&": "https://google.com/?a=b&c=d&", | ||
"https://google.com?a=b&c=d&e=": "https://google.com/?a=b&c=d&e=", | ||
"https://google.com?a=b&c=d&e=f": "https://google.com/?a=b&c=d&e=f" | ||
}; | ||
Object.keys(LINK_MAP).forEach((input) => { | ||
it('should auto convert links to anchor: ' + input, function() { | ||
editor.insertHTML(input); | ||
var link = editor.getDocument().querySelector('a'); | ||
expect(link.href, 'to contain', LINK_MAP[input]); | ||
editor.setHTML(''); | ||
}); | ||
}); | ||
it('should auto convert a part of the link to an anchor', function() { | ||
editor.insertHTML(` | ||
dew@fre.fr dewdwe @dew | ||
`); | ||
var link = editor.getDocument().querySelector('a'); | ||
expect(link.textContent, 'to be', 'dew@fre.fr'); | ||
expect(link.href, 'to be', 'mailto:dew@fre.fr'); | ||
editor.setHTML(''); | ||
}); | ||
it('should not auto convert non links to anchor', function() { | ||
editor.insertHTML(` | ||
dewdwe @dew | ||
deww.de | ||
monique.fre | ||
google.com | ||
`); | ||
var link = editor.getDocument().querySelector('a'); | ||
expect(link, 'to be', null); | ||
editor.setHTML(''); | ||
}); | ||
}); | ||
@@ -366,0 +425,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
267399
4976
504