diff --git a/build/squire-raw.js b/build/squire-raw.js index 0921684..b1bd333 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -17,11 +17,6 @@ var START_TO_END = 1; // Range.START_TO_END var END_TO_END = 2; // Range.END_TO_END var END_TO_START = 3; // Range.END_TO_START -var HIGHLIGHT_CLASS = 'highlight'; -var COLOUR_CLASS = 'colour'; -var FONT_FAMILY_CLASS = 'font'; -var FONT_SIZE_CLASS = 'size'; - var ZWS = '\u200B'; var win = doc.defaultView; @@ -309,11 +304,11 @@ function isOrContains ( parent, node ) { return false; } -function getPath ( node, root ) { +function getPath ( node, root, config ) { var path = ''; - var id, className, classNames, dir; + var id, className, classNames, dir, styleNames; if ( node && node !== root ) { - path = getPath( node.parentNode, root ); + path = getPath( node.parentNode, root, config ); if ( node.nodeType === ELEMENT_NODE ) { path += ( path ? '>' : '' ) + node.nodeName; if ( id = node.id ) { @@ -329,19 +324,20 @@ function getPath ( node, root ) { path += '[dir=' + dir + ']'; } if ( classNames ) { - if ( indexOf.call( classNames, HIGHLIGHT_CLASS ) > -1 ) { + styleNames = config.classNames; + if ( indexOf.call( classNames, styleNames.highlight ) > -1 ) { path += '[backgroundColor=' + node.style.backgroundColor.replace( / /g,'' ) + ']'; } - if ( indexOf.call( classNames, COLOUR_CLASS ) > -1 ) { + if ( indexOf.call( classNames, styleNames.colour ) > -1 ) { path += '[color=' + node.style.color.replace( / /g,'' ) + ']'; } - if ( indexOf.call( classNames, FONT_FAMILY_CLASS ) > -1 ) { + if ( indexOf.call( classNames, styleNames.fontFamily ) > -1 ) { path += '[fontFamily=' + node.style.fontFamily.replace( / /g,'' ) + ']'; } - if ( indexOf.call( classNames, FONT_SIZE_CLASS ) > -1 ) { + if ( indexOf.call( classNames, styleNames.fontSize ) > -1 ) { path += '[fontSize=' + node.style.fontSize + ']'; } } @@ -1789,18 +1785,18 @@ var fontSizes = { var styleToSemantic = { backgroundColor: { regexp: notWS, - replace: function ( doc, colour ) { + replace: function ( doc, classNames, colour ) { return createElement( doc, 'SPAN', { - 'class': HIGHLIGHT_CLASS, + 'class': classNames.highlight, style: 'background-color:' + colour }); } }, color: { regexp: notWS, - replace: function ( doc, colour ) { + replace: function ( doc, classNames, colour ) { return createElement( doc, 'SPAN', { - 'class': COLOUR_CLASS, + 'class': classNames.colour, style: 'color:' + colour }); } @@ -1819,18 +1815,18 @@ var styleToSemantic = { }, fontFamily: { regexp: notWS, - replace: function ( doc, family ) { + replace: function ( doc, classNames, family ) { return createElement( doc, 'SPAN', { - 'class': FONT_FAMILY_CLASS, + 'class': classNames.fontFamily, style: 'font-family:' + family }); } }, fontSize: { regexp: notWS, - replace: function ( doc, size ) { + replace: function ( doc, classNames, size ) { return createElement( doc, 'SPAN', { - 'class': FONT_SIZE_CLASS, + 'class': classNames.fontSize, style: 'font-size:' + size }); } @@ -1852,7 +1848,7 @@ var replaceWithTag = function ( tag ) { }; }; -var replaceStyles = function ( node, parent ) { +var replaceStyles = function ( node, parent, config ) { var style = node.style; var doc = node.ownerDocument; var attr, converter, css, newTreeBottom, newTreeTop, el; @@ -1861,7 +1857,7 @@ var replaceStyles = function ( node, parent ) { converter = styleToSemantic[ attr ]; css = style[ attr ]; if ( css && converter.regexp.test( css ) ) { - el = converter.replace( doc, css ); + el = converter.replace( doc, config.classNames, css ); if ( !newTreeTop ) { newTreeTop = el; } @@ -1892,16 +1888,17 @@ var stylesRewriters = { EM: replaceWithTag( 'I' ), INS: replaceWithTag( 'U' ), STRIKE: replaceWithTag( 'S' ), - FONT: function ( node, parent ) { - var face = node.face, - size = node.size, - colour = node.color, - doc = node.ownerDocument, - fontSpan, sizeSpan, colourSpan, - newTreeBottom, newTreeTop; + FONT: function ( node, parent, config ) { + var face = node.face; + var size = node.size; + var colour = node.color; + var doc = node.ownerDocument; + var classNames = config.classNames; + var fontSpan, sizeSpan, colourSpan; + var newTreeBottom, newTreeTop; if ( face ) { fontSpan = createElement( doc, 'SPAN', { - 'class': FONT_FAMILY_CLASS, + 'class': classNames.fontFamily, style: 'font-family:' + face }); newTreeTop = fontSpan; @@ -1909,7 +1906,7 @@ var stylesRewriters = { } if ( size ) { sizeSpan = createElement( doc, 'SPAN', { - 'class': FONT_SIZE_CLASS, + 'class': classNames.fontSize, style: 'font-size:' + fontSizes[ size ] + 'px' }); if ( !newTreeTop ) { @@ -1925,7 +1922,7 @@ var stylesRewriters = { colour = '#' + colour; } colourSpan = createElement( doc, 'SPAN', { - 'class': COLOUR_CLASS, + 'class': classNames.colour, style: 'color:' + colour }); if ( !newTreeTop ) { @@ -1943,9 +1940,9 @@ var stylesRewriters = { newTreeBottom.appendChild( empty( node ) ); return newTreeBottom; }, - TT: function ( node, parent ) { + TT: function ( node, parent, config ) { var el = createElement( node.ownerDocument, 'SPAN', { - 'class': FONT_FAMILY_CLASS, + 'class': config.classNames.fontFamily, style: 'font-family:menlo,consolas,"courier new",monospace' }); parent.replaceChild( el, node ); @@ -1969,7 +1966,7 @@ var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT, function () { and whitespace nodes. 2. Convert inline tags into our preferred format. */ -var cleanTree = function cleanTree ( node, preserveWS ) { +var cleanTree = function cleanTree ( node, config, preserveWS ) { var children = node.childNodes, nonInlineParent, i, l, child, nodeName, nodeType, rewriter, childLength, startsWithWS, endsWithWS, data, sibling; @@ -1988,7 +1985,7 @@ var cleanTree = function cleanTree ( node, preserveWS ) { if ( nodeType === ELEMENT_NODE ) { childLength = child.childNodes.length; if ( rewriter ) { - child = rewriter( child, node ); + child = rewriter( child, node, config ); } else if ( blacklist.test( nodeName ) ) { node.removeChild( child ); i -= 1; @@ -2001,7 +1998,8 @@ var cleanTree = function cleanTree ( node, preserveWS ) { continue; } if ( childLength ) { - cleanTree( child, preserveWS || ( nodeName === 'PRE' ) ); + cleanTree( child, config, + preserveWS || ( nodeName === 'PRE' ) ); } } else { if ( nodeType === TEXT_NODE ) { @@ -2634,6 +2632,12 @@ proto.setConfig = function ( config ) { li: null, a: null }, + classNames: { + colour: 'colour', + fontFamily: 'font', + fontSize: 'size', + highlight: 'highlight' + }, leafNodeNames: leafNodeNames, undo: { documentSizeThreshold: -1, // -1 means no threshold @@ -3078,7 +3082,7 @@ proto._updatePath = function ( range, force ) { this._lastAnchorNode = anchor; this._lastFocusNode = focus; newPath = ( anchor && focus ) ? ( anchor === focus ) ? - getPath( focus, this._root ) : '(selection)' : ''; + getPath( focus, this._root, this._config ) : '(selection)' : ''; if ( this._path !== newPath ) { this._path = newPath; this.fireEvent( 'pathChange', { path: newPath } ); @@ -4149,7 +4153,7 @@ proto.setHTML = function ( html ) { frag.appendChild( empty( div ) ); } - cleanTree( frag ); + cleanTree( frag, config ); cleanupBRs( frag, root, false ); fixContainer( frag, root ); @@ -4335,7 +4339,7 @@ proto.insertHTML = function ( html, isPaste ) { }; addLinks( frag, frag, this ); - cleanTree( frag ); + cleanTree( frag, config ); cleanupBRs( frag, root, false ); removeEmptyInlines( frag ); frag.normalize(); @@ -4472,57 +4476,61 @@ proto.removeLink = function () { }; proto.setFontFace = function ( name ) { + var className = this._config.classNames.fontFamily; this.changeFormat( name ? { tag: 'SPAN', attributes: { - 'class': FONT_FAMILY_CLASS, + 'class': className, style: 'font-family: ' + name + ', sans-serif;' } } : null, { tag: 'SPAN', - attributes: { 'class': FONT_FAMILY_CLASS } + attributes: { 'class': className } }); return this.focus(); }; proto.setFontSize = function ( size ) { + var className = this._config.classNames.fontSize; this.changeFormat( size ? { tag: 'SPAN', attributes: { - 'class': FONT_SIZE_CLASS, + 'class': className, style: 'font-size: ' + ( typeof size === 'number' ? size + 'px' : size ) } } : null, { tag: 'SPAN', - attributes: { 'class': FONT_SIZE_CLASS } + attributes: { 'class': className } }); return this.focus(); }; proto.setTextColour = function ( colour ) { + var className = this._config.classNames.colour; this.changeFormat( colour ? { tag: 'SPAN', attributes: { - 'class': COLOUR_CLASS, + 'class': className, style: 'color:' + colour } } : null, { tag: 'SPAN', - attributes: { 'class': COLOUR_CLASS } + attributes: { 'class': className } }); return this.focus(); }; proto.setHighlightColour = function ( colour ) { + var className = this._config.classNames.highlight; this.changeFormat( colour ? { tag: 'SPAN', attributes: { - 'class': HIGHLIGHT_CLASS, + 'class': className, style: 'background-color:' + colour } } : colour, { tag: 'SPAN', - attributes: { 'class': HIGHLIGHT_CLASS } + attributes: { 'class': className } }); return this.focus(); }; diff --git a/build/squire.js b/build/squire.js index 3542aa7..af379b6 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1,2 +1,2 @@ -!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function o(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function i(e){return e.nodeType===w&&!!ge[e.nodeName]}function r(e){switch(e.nodeType){case F:return ve;case w:case H:if(ce&&Ce.has(e))return Ce.get(e);break;default:return me}var t;return t=o(e.childNodes,a)?pe.test(e.nodeName)?ve:_e:Ne,ce&&Ce.set(e,t),t}function a(e){return r(e)===ve}function s(e){return r(e)===_e}function d(e){return r(e)===Ne}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){var n,o,i,r,a="";return e&&e!==t&&(a=v(e.parentNode,t),e.nodeType===w&&(a+=(a?">":"")+e.nodeName,(n=e.id)&&(a+="#"+n),(o=e.className.trim())&&(i=o.split(/\s\s*/),i.sort(),a+=".",a+=i.join(".")),(r=e.dir)&&(a+="[dir="+r+"]"),i&&(ue.call(i,z)>-1&&(a+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),ue.call(i,q)>-1&&(a+="[color="+e.style.color.replace(/ /g,"")+"]"),ue.call(i,K)>-1&&(a+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),ue.call(i,G)>-1&&(a+="[fontSize="+e.style.fontSize+"]")))),a}function _(e){var t=e.nodeType;return t===w||t===H?e.childNodes.length:e.length||0}function N(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function 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;as?t.startOffset-=1:t.startOffset===s&&(t.startContainer=o,t.startOffset=_(o))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=o,t.endOffset=_(o))),N(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());k(n,t)}}function L(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};k(e,n),t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)}}function x(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;N(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),L(e,n),te&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function A(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)}N(e),n=!d(e),i.appendChild(S(e)),n&&E(i,t),r&&A(r,t)}else s&&(i=y(a,"DIV"),e.insertBefore(i,r),T(i,t))}function O(e){this.isShiftDown=e.shiftKey}function B(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?B(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,de&&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,le?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._restoreSelection=!1,this.addEventListener("blur",D),this.addEventListener("mousedown",U),this.addEventListener("touchstart",U),this.addEventListener("focus",P),this._awaitingPaste=!1,this.addEventListener(ee?"beforecut":"cut",nt),this.addEventListener("copy",ot),this.addEventListener("keydown",O),this.addEventListener("keyup",O),this.addEventListener(ee?"beforepaste":"paste",it),this.addEventListener("drop",rt),this.addEventListener(te?"keypress":"keydown",we),this._keyHandlers=Object.create(We),this.setConfig(t),ee&&(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 U(){this._restoreSelection=!1}function P(){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="highlight",q="colour",K="font",G="size",Z="​",j=e.defaultView,$=navigator.userAgent,Q=/Android/.test($),V=/iP(?:ad|hone|od)/.test($),Y=/Mac OS X/.test($),X=/Windows NT/.test($),J=/Gecko\//.test($),ee=/Trident\/[456]\./.test($),te=!!j.opera,ne=/Edge\//.test($),oe=!ne&&/WebKit\//.test($),ie=/Trident\/[4567]\./.test($),re=Y?"meta-":"ctrl-",ae=ee||te,se=ee||oe,de=ee,le="undefined"!=typeof MutationObserver,ce="undefined"!=typeof WeakMap,he=/[^ \t\r\n]/,ue=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var fe={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,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(fe[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(fe[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(fe[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}};var pe=/^(?:#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)$/,ge={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},me=0,ve=1,_e=2,Ne=3,Ce=ce?new WeakMap:null,Se=function(e,t){for(var n=e.childNodes;t&&e.nodeType===w;)e=n[t-1],n=e.childNodes,t=n.length;return e},ye=function(e,t){if(e.nodeType===w){var n=e.childNodes;if(t-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},xe=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=_(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))},Ae=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=ue.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!==_(s))break;i=s.parentNode,d=ue.call(i.childNodes,s)+1,s=i}e.setStart(r,a),e.setEnd(s,d)},Oe=function(e,t){var n,o=e.startContainer;return a(o)?n=c(o,t):o!==t&&s(o)?n=o:(n=Se(o,e.startOffset),n=h(n,t)),n&&Le(e,n,!0)?n:null},Be=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=ye(i,e.endOffset))||!m(t,n))for(n=t;o=n.lastChild;)n=o;n=c(n,t)}return n&&Le(e,n,!0)?n:null},Re=new n(null,4|W,function(e){return e.nodeType===F?he.test(e.data):"IMG"===e.nodeName}),De=function(e,t){var n,o=e.startContainer,i=e.startOffset;if(Re.root=null,o.nodeType===F){if(i)return!1;n=o}else if(n=ye(o,i),n&&!m(t,n)&&(n=null),!n&&(n=Se(o,i),n.nodeType===F&&n.length))return!1;return Re.currentNode=n,Re.root=Oe(e,t),!Re.previousNode()},Ue=function(e,t){var n,o=e.endContainer,i=e.endOffset;if(Re.root=null,o.nodeType===F){if((n=o.data.length)&&i-1||!J&&ue.call(i,"text/plain")>-1&&ue.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,_=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,N(C),e=C.firstChild,e&&e===C.lastChild&&"DIV"===e.nodeName&&(C=e),n+=C.innerHTML;t=u.createRange(g,m,v,_),u.setSelection(t),n&&u.insertHTML(n,!0)}catch(e){u.didError(e)}},0)},rt=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()},at=R.prototype,st=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()};at.setConfig=function(e){return e=B({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},leafNodeNames:ge,undo:{documentSizeThreshold:-1,undoLimit:-1},isInsertedHTMLSanitized:!0,isSetHTMLSanitized:!0,sanitizeToDOMFragment:"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?st:null},e,!0),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},at.createElement=function(e,t,n){return y(this._doc,e,t,n)},at.createDefaultBlock=function(e){var t=this._config;return T(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},at.didError=function(e){console.log(e)},at.getDocument=function(){return this._doc},at.getRoot=function(){return this._root},at.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 dt={pathChange:1,select:1,input:1,undoStateChange:1};at.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},at.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},at.handleEvent=function(e){this.fireEvent(e.type,e)},at.addEventListener=function(e,t){var n=this._events[e],o=this._root;return t?(n||(n=this._events[e]=[],dt[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)},at.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],dt[e]||("selectionchange"===e&&(i=this._doc),i.removeEventListener(e,this,!0)))}return this},at.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},at.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,Te(e,t),o=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),L(n,e)),o},at._moveCursorTo=function(e){var t=this._root,n=this.createRange(t,e?0:t.childNodes.length);return xe(n),this.setSelection(n),this},at.moveCursorToStart=function(){return this._moveCursorTo(!0)},at.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var lt=function(e){return e._win.getSelection()||null};at.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused)if(Q&&!this._restoreSelection)D.call(this),this.blur(),this.focus();else{V&&this._win.focus();var t=lt(this);t&&(t.removeAllRanges(),t.addRange(e))}else D.call(this);return this},at.getSelection=function(){var e,t,n,o,r=lt(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},at.getSelectedText=function(){var e=this.getSelection();if(!e||e.collapsed)return"";var t,o=new n(e.commonAncestorContainer,4|W,function(t){return Le(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},at.getPath=function(){return this._path};var ct=function(e,t){for(var o,i,r,s=new n(e,4,function(){return!0},!1);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)&&!_(i));break}i.deleteData(r,1)}};at._didAddZWS=function(){this._hasZWS=!0},at._removeZWS=function(){this._hasZWS&&(ct(this._root),this._hasZWS=!1)},at._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):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),this.fireEvent(e.collapsed?"cursor":"select",{range:e})}},at._updatePathOnEvent=function(e){var t=this;t._isFocused&&!t._willUpdatePath&&(t._willUpdatePath=!0,setTimeout(function(){t._willUpdatePath=!1,t._updatePath(t.getSelection())},0))},at.focus=function(){return this._root.focus(),ie&&this.fireEvent("focus"),this},at.blur=function(){return this._root.blur(),ie&&this.fireEvent("blur"),this};var ht="squire-selection-end";at._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:"squire-selection-start",type:"hidden"}),o=this.createElement("INPUT",{id:ht,type:"hidden"});Te(e,n),e.collapse(!1),Te(e,o),2&n.compareDocumentPosition(o)&&(n.id=ht,o.id="squire-selection-start",t=n,n=o,o=t),e.setStartAfter(n),e.setEndBefore(o)},at._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#squire-selection-start"),o=t.querySelector("#"+ht);if(n&&o){var i=n.parentNode,r=o.parentNode,a=ue.call(i.childNodes,n),s=ue.call(r.childNodes,o);i===r&&(s-=1),N(n),N(o),e||(e=this._doc.createRange()),e.setStart(i,a),e.setEnd(r,s),L(i,e),i!==r&&L(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},at._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(t<16||t>20)||!(t<33||t>45)||this._docWasChanged()},at._docWasChanged=function(){if(ce&&(Ce=new WeakMap),!this._ignoreAllChanges){ -if(le&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},at._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-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}},at.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._recordUndoState(e,this._isInUndoState),this._getRangeAndRemoveBookmark(e),this},at.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},at.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(e+1c&&h.splitText(c),h===s&&l&&(h=h.splitText(l),d===s&&(d=h,c-=l),s=h,l=0),i=this.createElement(e,t),C(h,i),i.appendChild(h))}while(r.nextNode());d.nodeType!==F&&(h.nodeType===F?(d=h,c=h.length):(d=h.parentNode,c=1)),o=this.createRange(s,l,d,c)}return o},at._removeFormat=function(e,t,n,o){this._saveRangeToBookmark(n);var i,r=this._doc;n.collapsed&&(se?(i=r.createTextNode(Z),this._didAddZWS()):i=r.createTextNode(""),Te(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(!Le(n,e,!1)){var o,i,r=e.nodeType===F;if(!Le(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 Le(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];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1),L(s,n),n},at.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),le||this._docWasChanged(),this):this};var ut={DT:"DD",DD:"DT",LI:"LI",PRE:"PRE"},ft=function(e,t,n,o){var i=ut[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),C(a,t),t.appendChild(S(a)),a=t),a};at.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var o=this._root,i=Oe(n,o),r=Be(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),le||this._docWasChanged()),this},at.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._recordUndoState(t,this._isInUndoState);var n,o=this._root;return Pe(t,o),Ae(t,o,o,o),n=Ee(t,o,o),Te(t,e.call(this,n)),t.endOffset]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)(?:\?[^&?\s]+=[^&?\s]+(?:&[^&?\s]+=[^&?\s]+)*)?/i,Tt=function(e,t,o){for(var i,r,a,s,d,l,c,h=e.ownerDocument,u=new n(e,4,function(e){return!g(e,t,"A")},!1),f=o._config.tagAttributes.a;i=u.nextNode();)for(r=i.data,a=i.parentNode;s=yt.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",B({href:s[1]?/^(?:ht|f)tps?:/i.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[0]},f,!1)),c.textContent=r.slice(d,l),a.insertBefore(c,i),i.data=r=r.slice(l)};at.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=""+e+""),/<\/tr>((?!<\/table>)[\s\S])*$/i.test(e)&&(e=""+e+"
"),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},Tt(r,r,this),Ve(r),et(r,a,!1),Ye(r),r.normalize();s=h(s,r);)T(s,a);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(ke(u,d.fragment,a),le||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 Et=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};at.insertPlainText=function(e,t){var n,o,i,r,a=e.split("\n"),s=this._config,d=s.blockTag,l=s.blockAttributes,c="",h="<"+d;for(n in l)h+=" "+n+'="'+Et(l[n])+'"';for(h+=">",o=0,i=a.length;o")+c;return this.insertHTML(a.join(""),t)};var bt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};at.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},at.bold=bt("changeFormat",{tag:"B"}),at.italic=bt("changeFormat",{tag:"I"}),at.underline=bt("changeFormat",{tag:"U"}),at.strikethrough=bt("changeFormat",{tag:"S"}),at.subscript=bt("changeFormat",{tag:"SUB"},{tag:"SUP"}),at.superscript=bt("changeFormat",{tag:"SUP"},{tag:"SUB"}),at.removeBold=bt("changeFormat",null,{tag:"B"}),at.removeItalic=bt("changeFormat",null,{tag:"I"}),at.removeUnderline=bt("changeFormat",null,{tag:"U"}),at.removeStrikethrough=bt("changeFormat",null,{tag:"S"}),at.removeSubscript=bt("changeFormat",null,{tag:"SUB"}),at.removeSuperscript=bt("changeFormat",null,{tag:"SUP"}),at.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var o=e.indexOf(":")+1;if(o)for(;"/"===e[o];)o+=1;Te(n,this._doc.createTextNode(e.slice(o)))}return t=B(B({href:e},t,!0),this._config.tagAttributes.a,!1),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},at.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},at.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{class:K,style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{class:K}}),this.focus()},at.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{class:G,style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{class:G}}),this.focus()},at.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{class:q,style:"color:"+e}}:null,{tag:"SPAN",attributes:{class:q}}),this.focus()},at.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{class:z,style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{class:z}}),this.focus()},at.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()},at.setTextDirection=function(e){return this.forEachBlock(function(t){e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()},at.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||(Pe(e,t),n=t),n.nodeType===F)return this;this.saveUndoState(e),Ae(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=ue.call(i,p),c=ue.call(i,o)+1):(d=ue.call(i,f),c=d),e.setStart(n,d),e.setEnd(n,c),L(n,e),xe(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},at.increaseQuoteLevel=bt("modifyBlocks",pt),at.decreaseQuoteLevel=bt("modifyBlocks",gt),at.makeUnorderedList=bt("modifyBlocks",_t),at.makeOrderedList=bt("modifyBlocks",Nt),at.removeList=bt("modifyBlocks",Ct),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=N,R.replaceWith=C,R.empty=S,R.getNodeBefore=Se,R.getNodeAfter=ye,R.insertNodeInRange=Te,R.extractContentsOfRange=Ee,R.deleteContentsOfRange=be,R.insertTreeFragmentIntoRange=ke,R.isNodeContainedInRange=Le,R.moveRangeBoundariesDownTree=xe,R.moveRangeBoundariesUpTree=Ae,R.getStartBlockOfRange=Oe,R.getEndBlockOfRange=Be,R.contentWalker=Re,R.rangeDoesStartAtBlockBoundary=De,R.rangeDoesEndAtBlockBoundary=Ue,R.expandRangeToBlockBoundaries=Pe,R.onPaste=it,R.addLinks=Tt,R.splitBlock=ft,R.startSelectionId="squire-selection-start",R.endSelectionId=ht,"object"==typeof exports?module.exports=R:"function"==typeof define&&define.amd?define(function(){return R}):(j.Squire=R,top!==j&&"true"===e.documentElement.getAttribute("data-squireinit")&&(j.editor=new R(e),j.onEditorLoad&&(j.onEditorLoad(j.editor),j.onEditorLoad=null)))}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function i(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(e){return e.nodeType===w&&!!he[e.nodeName]}function r(e){switch(e.nodeType){case F:return fe;case w:case H:if(ae&&me.has(e))return me.get(e);break;default:return ue}var t;return t=i(e.childNodes,a)?ce.test(e.nodeName)?fe:pe:ge,ae&&me.set(e,t),t}function a(e){return r(e)===fe}function s(e){return r(e)===pe}function d(e){return r(e)===ge}function l(e,t){var i=new n(t,W,s);return i.currentNode=e,i}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!o(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&"A"!==e.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function p(e,t,n){if(e.nodeName!==t)return!1;for(var i in n)if(e.getAttribute(i)!==n[i])return!1;return!0}function g(e,t,n,i){for(;e&&e!==t;){if(p(e,n,i))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 i,o,r,a,s,d="";return e&&e!==t&&(d=v(e.parentNode,t,n),e.nodeType===w&&(d+=(d?">":"")+e.nodeName,(i=e.id)&&(d+="#"+i),(o=e.className.trim())&&(r=o.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 N(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 C(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,i=n?n.length:0;i--;)t.appendChild(e.firstChild);return t}function y(e,n,i,o){var r,a,s,d=e.createElement(n);if(i instanceof Array&&(o=i,i=null),i)for(r in i)i[r]!==t&&d.setAttribute(r,i[r]);if(o)for(a=0,s=o.length;as?t.startOffset-=1:t.startOffset===s&&(t.startContainer=i,t.startOffset=N(i))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=i,t.endOffset=N(i))),_(n),n.nodeType===F?i.appendData(n.data):d.push(S(n));else if(n.nodeType===w){for(o=d.length;o--;)n.appendChild(d.pop());k(n,t)}}function L(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};k(e,n),t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)}}function x(e,t,n,i){for(var o,r,a,s=t;(o=s.parentNode)&&o!==i&&o.nodeType===w&&1===o.childNodes.length;)s=o;_(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),L(e,n),Y&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function A(e,t){var n,i,o=e.previousSibling,r=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||r&&/^[OU]L$/.test(r.nodeName))if(o&&f(o,e)){if(!d(o)){if(!s)return;i=y(a,"DIV"),i.appendChild(S(o)),o.appendChild(i)}_(e),n=!d(e),o.appendChild(S(e)),n&&E(o,t),r&&A(r,t)}else s&&(o=y(a,"DIV"),e.insertBefore(o,r),T(o,t))}function O(e){this.isShiftDown=e.shiftKey}function B(e,t,n){var i,o;if(e||(e={}),t)for(i in t)!n&&i in e||(o=t[i],e[i]=o&&o.constructor===Object?B(e[i],o,n):o);return e}function R(e,t){e.nodeType===M&&(e=e.body);var n,i=e.ownerDocument,o=i.defaultView;this._win=o,this._doc=i,this._root=e,this._events={},this._isFocused=!1,this._lastSelection=null,oe&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._willUpdatePath=!1,"onselectionchange"in i?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",U),this.addEventListener("touchstart",U),this.addEventListener("focus",P),this._awaitingPaste=!1,this.addEventListener(V?"beforecut":"cut",Xe),this.addEventListener("copy",Je),this.addEventListener("keydown",O),this.addEventListener("keyup",O),this.addEventListener(V?"beforepaste":"paste",et),this.addEventListener("drop",tt),this.addEventListener(Y?"keypress":"keydown",De),this._keyHandlers=Object.create(we),this.setConfig(t),V&&(o.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,i=this.parentNode,o=this.length-e;return n?i.insertBefore(t,n):i.appendChild(t),o&&this.deleteData(e,o),t}),e.setAttribute("contenteditable","true");try{i.execCommand("enableObjectResizing",!1,"false"),i.execCommand("enableInlineTableEditing",!1,"false")}catch(e){}e.__squire__=this,this.setHTML("")}function D(){this._restoreSelection=!0}function U(){this._restoreSelection=!1}function P(){this._restoreSelection&&this.setSelection(this._lastSelection)}function I(e,t,n){var i,o;for(i=t.firstChild;i;i=o){if(o=i.nextSibling,a(i)){if(i.nodeType===F||"BR"===i.nodeName||"IMG"===i.nodeName){n.appendChild(i);continue}}else if(s(i)){n.appendChild(e.createDefaultBlock([I(e,i,e._doc.createDocumentFragment())]));continue}I(e,i,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,ie=V||J,oe=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};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)(e=t.nextSibling)||(t=t.parentNode);if(!e)return null;if(le[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(le[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,i=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)(e=t.previousSibling)||(t=t.parentNode);if(!e)return null;if(le[e.nodeType]&i&&o(e))return this.currentNode=e,e;t=e}};var ce=/^(?:#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)$/,he={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},ue=0,fe=1,pe=2,ge=3,me=ae?new WeakMap:null,ve=function(e,t){for(var n=e.childNodes;t&&e.nodeType===w;)e=n[t-1],n=e.childNodes,t=n.length;return e},Ne=function(e,t){if(e.nodeType===w){var n=e.childNodes;if(t-1,r=e.compareBoundaryPoints(1,i)<1;return!o&&!r}var a=e.compareBoundaryPoints(0,i)<1,s=e.compareBoundaryPoints(2,i)>-1;return a&&s},Ee=function(e){for(var t,n=e.startContainer,i=e.startOffset,r=e.endContainer,a=e.endOffset,s=!0;n.nodeType!==F&&(t=n.childNodes[i])&&!o(t);)n=t,i=0;if(a)for(;r.nodeType!==F;){if(!(t=r.childNodes[a-1])||o(t)){if(s&&t&&"BR"===t.nodeName){a-=1,s=!1;continue}break}r=t,a=N(r)}else for(;r.nodeType!==F&&(t=r.firstChild)&&!o(t);)r=t;e.collapsed?(e.setStart(r,a),e.setEnd(n,i)):(e.setStart(n,i),e.setEnd(r,a))},be=function(e,t,n,i){var o,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!==i;)o=r.parentNode,a=de.call(o.childNodes,r),r=o;for(;;){if(l&&s.nodeType!==F&&s.childNodes[d]&&"BR"===s.childNodes[d].nodeName&&(d+=1,l=!1),s===n||s===i||d!==N(s))break;o=s.parentNode,d=de.call(o.childNodes,s)+1,s=o}e.setStart(r,a),e.setEnd(s,d)},ke=function(e,t){var n,i=e.startContainer;return a(i)?n=c(i,t):i!==t&&s(i)?n=i:(n=ve(i,e.startOffset),n=h(n,t)),n&&Te(e,n,!0)?n:null},Le=function(e,t){var n,i,o=e.endContainer;if(a(o))n=c(o,t);else if(o!==t&&s(o))n=o;else{if(!(n=Ne(o,e.endOffset))||!m(t,n))for(n=t;i=n.lastChild;)n=i;n=c(n,t)}return n&&Te(e,n,!0)?n:null},xe=new n(null,4|W,function(e){return e.nodeType===F?se.test(e.data):"IMG"===e.nodeName}),Ae=function(e,t){var n,i=e.startContainer,o=e.startOffset;if(xe.root=null,i.nodeType===F){if(o)return!1;n=i}else if(n=Ne(i,o),n&&!m(t,n)&&(n=null),!n&&(n=ve(i,o),n.nodeType===F&&n.length))return!1;return xe.currentNode=n,xe.root=ke(e,t),!xe.previousNode()},Oe=function(e,t){var n,i=e.endContainer,o=e.endOffset;if(xe.root=null,i.nodeType===F){if((n=i.data.length)&&o-1||!Q&&de.call(o,"text/plain")>-1&&de.call(o,"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="",i=C;C=i;)i=C.nextSibling,_(C),e=C.firstChild,e&&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)},tt=function(e){for(var t=e.dataTransfer.types,n=t.length,i=!1,o=!1;n--;)switch(t[n]){case"text/plain":i=!0;break;case"text/html":o=!0;break;default:return}(o||i)&&this.saveUndoState()},nt=R.prototype,it=function(e,t,n){var i=n._doc,o=e?DOMPurify.sanitize(e,{ALLOW_UNKNOWN_PROTOCOLS:!0,WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}):null;return o?i.importNode(o,!0):i.createDocumentFragment()};nt.setConfig=function(e){return e=B({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:he,undo:{documentSizeThreshold:-1,undoLimit:-1},isInsertedHTMLSanitized:!0,isSetHTMLSanitized:!0,sanitizeToDOMFragment:"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?it:null},e,!0),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},nt.createElement=function(e,t,n){return y(this._doc,e,t,n)},nt.createDefaultBlock=function(e){var t=this._config;return T(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},nt.didError=function(e){console.log(e)},nt.getDocument=function(){return this._doc},nt.getRoot=function(){return this._root},nt.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 ot={pathChange:1,select:1,input:1,undoStateChange:1};nt.fireEvent=function(e,t){var n,i,o,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(),i=r.length;i--;){o=r[i];try{o.handleEvent?o.handleEvent(t):o.call(this,t)}catch(t){t.details="Squire: fireEvent error. Event type: "+e,this.didError(t)}}return this},nt.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},nt.handleEvent=function(e){this.fireEvent(e.type,e)},nt.addEventListener=function(e,t){var n=this._events[e],i=this._root;return t?(n||(n=this._events[e]=[],ot[e]||("selectionchange"===e&&(i=this._doc),i.addEventListener(e,this,!0))),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},nt.removeEventListener=function(e,t){var n,i=this._events[e],o=this._root;if(i){if(t)for(n=i.length;n--;)i[n]===t&&i.splice(n,1);else i.length=0;i.length||(delete this._events[e],ot[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},nt.createRange=function(e,t,n,i){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,i):o.setEnd(e,t),o},nt.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,i=e.getBoundingClientRect();return i&&!i.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=z,_e(e,t),i=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),L(n,e)),i},nt._moveCursorTo=function(e){var t=this._root,n=this.createRange(t,e?0:t.childNodes.length);return Ee(n),this.setSelection(n),this},nt.moveCursorToStart=function(){return this._moveCursorTo(!0)},nt.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var rt=function(e){return e._win.getSelection()||null};nt.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=rt(this);t&&(t.removeAllRanges(),t.addRange(e))}else D.call(this);return this},nt.getSelection=function(){var e,t,n,i,r=rt(this),a=this._root;return this._isFocused&&r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&o(t)&&e.setStartBefore(t),n&&o(n)&&e.setEndBefore(n)),e&&m(a,e.commonAncestorContainer)?this._lastSelection=e:(e=this._lastSelection,i=e.commonAncestorContainer,m(i.ownerDocument,i)||(e=null)),e||(e=this.createRange(a.firstChild,0)),e},nt.getSelectedText=function(){var e=this.getSelection();if(!e||e.collapsed)return"";var t,i=new n(e.commonAncestorContainer,4|W,function(t){return Te(e,t,!0)}),o=e.startContainer,r=e.endContainer,s=i.currentNode=o,d="",l=!1;for(i.filter(s)||(s=i.nextNode());s;)s.nodeType===F?(t=s.data)&&/\S/.test(t)&&(s===r&&(t=t.slice(0,e.endOffset)),s===o&&(t=t.slice(e.startOffset)),d+=t,l=!0):("BR"===s.nodeName||l&&!a(s))&&(d+="\n",l=!1),s=i.nextNode();return d},nt.getPath=function(){return this._path};var at=function(e,t){for(var i,o,r,s=new n(e,4,function(){return!0},!1);o=s.nextNode();)for(;(r=o.data.indexOf(z))>-1&&(!t||o.parentNode!==t);){if(1===o.length){do{i=o.parentNode,i.removeChild(o),o=i,s.currentNode=i}while(a(o)&&!N(o));break}o.deleteData(r,1)}};nt._didAddZWS=function(){this._hasZWS=!0},nt._removeZWS=function(){this._hasZWS&&(at(this._root),this._hasZWS=!1)},nt._updatePath=function(e,t){if(e){var n,i=e.startContainer,o=e.endContainer;(t||i!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=i,this._lastFocusNode=o,n=i&&o?i===o?v(o,this._root,this._config):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),this.fireEvent(e.collapsed?"cursor":"select",{range:e})}},nt._updatePathOnEvent=function(e){var t=this;t._isFocused&&!t._willUpdatePath&&(t._willUpdatePath=!0,setTimeout(function(){t._willUpdatePath=!1,t._updatePath(t.getSelection())},0))},nt.focus=function(){return this._root.focus(),ee&&this.fireEvent("focus"),this},nt.blur=function(){return this._root.blur(),ee&&this.fireEvent("blur"),this};var st="squire-selection-end";nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:"squire-selection-start",type:"hidden"}),i=this.createElement("INPUT",{id:st,type:"hidden"});_e(e,n),e.collapse(!1),_e(e,i),2&n.compareDocumentPosition(i)&&(n.id=st,i.id="squire-selection-start",t=n,n=i,i=t),e.setStartAfter(n),e.setEndBefore(i)},nt._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#squire-selection-start"),i=t.querySelector("#"+st);if(n&&i){var o=n.parentNode,r=i.parentNode,a=de.call(o.childNodes,n),s=de.call(r.childNodes,i);o===r&&(s-=1),_(n),_(i),e||(e=this._doc.createRange()),e.setStart(o,a),e.setEnd(r,s),L(o,e),o!==r&&L(r,e),e.collapsed&&(o=e.startContainer,o.nodeType===F&&(r=o.childNodes[e.startOffset],r&&r.nodeType===F||(r=o.childNodes[e.startOffset-1]),r&&r.nodeType===F&&(e.setStart(r,0),e.collapse(!0))))} +return e||null},nt._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(t<16||t>20)||!(t<33||t>45)||this._docWasChanged()},nt._docWasChanged=function(){if(ae&&(me=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")}},nt._recordUndoState=function(e,t){if(!this._isInUndoState||t){var n,i=this._undoIndex,o=this._undoStack,r=this._config.undo,a=r.documentSizeThreshold,s=r.undoLimit;t||(i+=1),i-1&&2*n.length>a&&s>-1&&i>s&&(o.splice(0,i-s),i=s,this._undoStackLength=s),o[i]=n,this._undoIndex=i,this._undoStackLength+=1,this._isInUndoState=!0}},nt.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._recordUndoState(e,this._isInUndoState),this._getRangeAndRemoveBookmark(e),this},nt.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},nt.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(e+1c&&h.splitText(c),h===s&&l&&(h=h.splitText(l),d===s&&(d=h,c-=l),s=h,l=0),o=this.createElement(e,t),C(h,o),o.appendChild(h))}while(r.nextNode());d.nodeType!==F&&(h.nodeType===F?(d=h,c=h.length):(d=h.parentNode,c=1)),i=this.createRange(s,l,d,c)}return i},nt._removeFormat=function(e,t,n,i){this._saveRangeToBookmark(n);var o,r=this._doc;n.collapsed&&(ie?(o=r.createTextNode(z),this._didAddZWS()):o=r.createTextNode(""),_e(n,o));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(!Te(n,e,!1)){var i,o,r=e.nodeType===F;if(!Te(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(i=e.firstChild;i;i=o)o=i.nextSibling,f(i,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(i){return Te(n,i,!0)&&p(i,e,t)});return i||g.forEach(function(e){f(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,S(e))}),this._getRangeAndRemoveBookmark(n),o&&n.collapse(!1),L(s,n),n},nt.changeFormat=function(e,t,n,i){return n||(n=this.getSelection())?(this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,i)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),re||this._docWasChanged(),this):this};var dt={DT:"DD",DD:"DT",LI:"LI",PRE:"PRE"},lt=function(e,t,n,i){var o=dt[t.nodeName],r=null,a=b(n,i,t.parentNode,e._root),s=e._config;return o||(o=s.blockTag,r=s.blockAttributes),p(a,o,r)||(t=y(a.ownerDocument,o,r),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(S(a)),a=t),a};nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var i=this._root,o=ke(n,i),r=Le(n,i);if(o&&r)do{if(e(o)||o===r)break}while(o=h(o,i));return t&&(this.setSelection(n),this._updatePath(n,!0),re||this._docWasChanged()),this},nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._recordUndoState(t,this._isInUndoState);var n,i=this._root;return Be(t,i),be(t,i,i,i),n=Ce(t,i,i),_e(t,e.call(this,n)),t.endOffset]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)(?:\?[^&?\s]+=[^&?\s]+(?:&[^&?\s]+=[^&?\s]+)*)?/i,_t=function(e,t,i){for(var o,r,a,s,d,l,c,h=e.ownerDocument,u=new n(e,4,function(e){return!g(e,t,"A")},!1),f=i._config.tagAttributes.a;o=u.nextNode();)for(r=o.data,a=o.parentNode;s=Nt.exec(r);)d=s.index,l=d+s[0].length,d&&(c=h.createTextNode(r.slice(0,d)),a.insertBefore(c,o)),c=i.createElement("A",B({href:s[1]?/^(?:ht|f)tps?:/i.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[0]},f,!1)),c.textContent=r.slice(d,l),a.insertBefore(c,o),o.data=r=r.slice(l)};nt.insertHTML=function(e,t){var n,i,o,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"),i=e.lastIndexOf("\x3c!--EndFragment--\x3e"),n>-1&&i>-1&&(e=e.slice(n+20,i))),/<\/td>((?!<\/tr>)[\s\S])*$/i.test(e)&&(e=""+e+""),/<\/tr>((?!<\/table>)[\s\S])*$/i.test(e)&&(e=""+e+"
"),o=this.createElement("DIV"),o.innerHTML=e,r=f.createDocumentFragment(),r.appendChild(S(o))),this.saveUndoState(u);try{for(a=this._root,s=r,d={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},_t(r,r,this),Ze(r,l),Ve(r,a,!1),je(r),r.normalize();s=h(s,r);)T(s,a);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(ye(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 Ct=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};nt.insertPlainText=function(e,t){var n,i,o,r,a=e.split("\n"),s=this._config,d=s.blockTag,l=s.blockAttributes,c="",h="<"+d;for(n in l)h+=" "+n+'="'+Ct(l[n])+'"';for(h+=">",i=0,o=a.length;i")+c;return this.insertHTML(a.join(""),t)};var St=function(e,t,n){return function(){return this[e](t,n),this.focus()}};nt.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},nt.bold=St("changeFormat",{tag:"B"}),nt.italic=St("changeFormat",{tag:"I"}),nt.underline=St("changeFormat",{tag:"U"}),nt.strikethrough=St("changeFormat",{tag:"S"}),nt.subscript=St("changeFormat",{tag:"SUB"},{tag:"SUP"}),nt.superscript=St("changeFormat",{tag:"SUP"},{tag:"SUB"}),nt.removeBold=St("changeFormat",null,{tag:"B"}),nt.removeItalic=St("changeFormat",null,{tag:"I"}),nt.removeUnderline=St("changeFormat",null,{tag:"U"}),nt.removeStrikethrough=St("changeFormat",null,{tag:"S"}),nt.removeSubscript=St("changeFormat",null,{tag:"SUB"}),nt.removeSuperscript=St("changeFormat",null,{tag:"SUP"}),nt.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var i=e.indexOf(":")+1;if(i)for(;"/"===e[i];)i+=1;_e(n,this._doc.createTextNode(e.slice(i)))}return t=B(B({href:e},t,!0),this._config.tagAttributes.a,!1),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},nt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},nt.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()},nt.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()},nt.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()},nt.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()},nt.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()},nt.setTextDirection=function(e){return this.forEachBlock(function(t){e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()},nt.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||(Be(e,t),n=t),n.nodeType===F)return this;this.saveUndoState(e),be(e,n,n,t);for(var i,o,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;)i=p.nextSibling,h.appendChild(p),p=i;return I(this,h,u),u.normalize(),p=u.firstChild,i=u.lastChild,o=n.childNodes,p?(n.insertBefore(u,f),d=de.call(o,p),c=de.call(o,i)+1):(d=de.call(o,f),c=d),e.setStart(n,d),e.setEnd(n,c),L(n,e),Ee(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},nt.increaseQuoteLevel=St("modifyBlocks",ct),nt.decreaseQuoteLevel=St("modifyBlocks",ht),nt.makeUnorderedList=St("modifyBlocks",pt),nt.makeOrderedList=St("modifyBlocks",gt),nt.removeList=St("modifyBlocks",mt),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=C,R.empty=S,R.getNodeBefore=ve,R.getNodeAfter=Ne,R.insertNodeInRange=_e,R.extractContentsOfRange=Ce,R.deleteContentsOfRange=Se,R.insertTreeFragmentIntoRange=ye,R.isNodeContainedInRange=Te,R.moveRangeBoundariesDownTree=Ee,R.moveRangeBoundariesUpTree=be,R.getStartBlockOfRange=ke,R.getEndBlockOfRange=Le,R.contentWalker=xe,R.rangeDoesStartAtBlockBoundary=Ae,R.rangeDoesEndAtBlockBoundary=Oe,R.expandRangeToBlockBoundaries=Be,R.onPaste=et,R.addLinks=_t,R.splitBlock=lt,R.startSelectionId="squire-selection-start",R.endSelectionId=st,"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); \ No newline at end of file diff --git a/source/Clean.js b/source/Clean.js index 3fe01f1..f844b81 100644 --- a/source/Clean.js +++ b/source/Clean.js @@ -13,18 +13,18 @@ var fontSizes = { var styleToSemantic = { backgroundColor: { regexp: notWS, - replace: function ( doc, colour ) { + replace: function ( doc, classNames, colour ) { return createElement( doc, 'SPAN', { - 'class': HIGHLIGHT_CLASS, + 'class': classNames.highlight, style: 'background-color:' + colour }); } }, color: { regexp: notWS, - replace: function ( doc, colour ) { + replace: function ( doc, classNames, colour ) { return createElement( doc, 'SPAN', { - 'class': COLOUR_CLASS, + 'class': classNames.colour, style: 'color:' + colour }); } @@ -43,18 +43,18 @@ var styleToSemantic = { }, fontFamily: { regexp: notWS, - replace: function ( doc, family ) { + replace: function ( doc, classNames, family ) { return createElement( doc, 'SPAN', { - 'class': FONT_FAMILY_CLASS, + 'class': classNames.fontFamily, style: 'font-family:' + family }); } }, fontSize: { regexp: notWS, - replace: function ( doc, size ) { + replace: function ( doc, classNames, size ) { return createElement( doc, 'SPAN', { - 'class': FONT_SIZE_CLASS, + 'class': classNames.fontSize, style: 'font-size:' + size }); } @@ -76,7 +76,7 @@ var replaceWithTag = function ( tag ) { }; }; -var replaceStyles = function ( node, parent ) { +var replaceStyles = function ( node, parent, config ) { var style = node.style; var doc = node.ownerDocument; var attr, converter, css, newTreeBottom, newTreeTop, el; @@ -85,7 +85,7 @@ var replaceStyles = function ( node, parent ) { converter = styleToSemantic[ attr ]; css = style[ attr ]; if ( css && converter.regexp.test( css ) ) { - el = converter.replace( doc, css ); + el = converter.replace( doc, config.classNames, css ); if ( !newTreeTop ) { newTreeTop = el; } @@ -116,16 +116,17 @@ var stylesRewriters = { EM: replaceWithTag( 'I' ), INS: replaceWithTag( 'U' ), STRIKE: replaceWithTag( 'S' ), - FONT: function ( node, parent ) { - var face = node.face, - size = node.size, - colour = node.color, - doc = node.ownerDocument, - fontSpan, sizeSpan, colourSpan, - newTreeBottom, newTreeTop; + FONT: function ( node, parent, config ) { + var face = node.face; + var size = node.size; + var colour = node.color; + var doc = node.ownerDocument; + var classNames = config.classNames; + var fontSpan, sizeSpan, colourSpan; + var newTreeBottom, newTreeTop; if ( face ) { fontSpan = createElement( doc, 'SPAN', { - 'class': FONT_FAMILY_CLASS, + 'class': classNames.fontFamily, style: 'font-family:' + face }); newTreeTop = fontSpan; @@ -133,7 +134,7 @@ var stylesRewriters = { } if ( size ) { sizeSpan = createElement( doc, 'SPAN', { - 'class': FONT_SIZE_CLASS, + 'class': classNames.fontSize, style: 'font-size:' + fontSizes[ size ] + 'px' }); if ( !newTreeTop ) { @@ -149,7 +150,7 @@ var stylesRewriters = { colour = '#' + colour; } colourSpan = createElement( doc, 'SPAN', { - 'class': COLOUR_CLASS, + 'class': classNames.colour, style: 'color:' + colour }); if ( !newTreeTop ) { @@ -167,9 +168,9 @@ var stylesRewriters = { newTreeBottom.appendChild( empty( node ) ); return newTreeBottom; }, - TT: function ( node, parent ) { + TT: function ( node, parent, config ) { var el = createElement( node.ownerDocument, 'SPAN', { - 'class': FONT_FAMILY_CLASS, + 'class': config.classNames.fontFamily, style: 'font-family:menlo,consolas,"courier new",monospace' }); parent.replaceChild( el, node ); @@ -193,7 +194,7 @@ var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT, function () { and whitespace nodes. 2. Convert inline tags into our preferred format. */ -var cleanTree = function cleanTree ( node, preserveWS ) { +var cleanTree = function cleanTree ( node, config, preserveWS ) { var children = node.childNodes, nonInlineParent, i, l, child, nodeName, nodeType, rewriter, childLength, startsWithWS, endsWithWS, data, sibling; @@ -212,7 +213,7 @@ var cleanTree = function cleanTree ( node, preserveWS ) { if ( nodeType === ELEMENT_NODE ) { childLength = child.childNodes.length; if ( rewriter ) { - child = rewriter( child, node ); + child = rewriter( child, node, config ); } else if ( blacklist.test( nodeName ) ) { node.removeChild( child ); i -= 1; @@ -225,7 +226,8 @@ var cleanTree = function cleanTree ( node, preserveWS ) { continue; } if ( childLength ) { - cleanTree( child, preserveWS || ( nodeName === 'PRE' ) ); + cleanTree( child, config, + preserveWS || ( nodeName === 'PRE' ) ); } } else { if ( nodeType === TEXT_NODE ) { diff --git a/source/Constants.js b/source/Constants.js index a33a793..0c3a01d 100644 --- a/source/Constants.js +++ b/source/Constants.js @@ -13,11 +13,6 @@ var START_TO_END = 1; // Range.START_TO_END var END_TO_END = 2; // Range.END_TO_END var END_TO_START = 3; // Range.END_TO_START -var HIGHLIGHT_CLASS = 'highlight'; -var COLOUR_CLASS = 'colour'; -var FONT_FAMILY_CLASS = 'font'; -var FONT_SIZE_CLASS = 'size'; - var ZWS = '\u200B'; var win = doc.defaultView; diff --git a/source/Editor.js b/source/Editor.js index 51cec37..abefa21 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -171,6 +171,12 @@ proto.setConfig = function ( config ) { li: null, a: null }, + classNames: { + colour: 'colour', + fontFamily: 'font', + fontSize: 'size', + highlight: 'highlight' + }, leafNodeNames: leafNodeNames, undo: { documentSizeThreshold: -1, // -1 means no threshold @@ -615,7 +621,7 @@ proto._updatePath = function ( range, force ) { this._lastAnchorNode = anchor; this._lastFocusNode = focus; newPath = ( anchor && focus ) ? ( anchor === focus ) ? - getPath( focus, this._root ) : '(selection)' : ''; + getPath( focus, this._root, this._config ) : '(selection)' : ''; if ( this._path !== newPath ) { this._path = newPath; this.fireEvent( 'pathChange', { path: newPath } ); @@ -1686,7 +1692,7 @@ proto.setHTML = function ( html ) { frag.appendChild( empty( div ) ); } - cleanTree( frag ); + cleanTree( frag, config ); cleanupBRs( frag, root, false ); fixContainer( frag, root ); @@ -1872,7 +1878,7 @@ proto.insertHTML = function ( html, isPaste ) { }; addLinks( frag, frag, this ); - cleanTree( frag ); + cleanTree( frag, config ); cleanupBRs( frag, root, false ); removeEmptyInlines( frag ); frag.normalize(); @@ -2009,57 +2015,61 @@ proto.removeLink = function () { }; proto.setFontFace = function ( name ) { + var className = this._config.classNames.fontFamily; this.changeFormat( name ? { tag: 'SPAN', attributes: { - 'class': FONT_FAMILY_CLASS, + 'class': className, style: 'font-family: ' + name + ', sans-serif;' } } : null, { tag: 'SPAN', - attributes: { 'class': FONT_FAMILY_CLASS } + attributes: { 'class': className } }); return this.focus(); }; proto.setFontSize = function ( size ) { + var className = this._config.classNames.fontSize; this.changeFormat( size ? { tag: 'SPAN', attributes: { - 'class': FONT_SIZE_CLASS, + 'class': className, style: 'font-size: ' + ( typeof size === 'number' ? size + 'px' : size ) } } : null, { tag: 'SPAN', - attributes: { 'class': FONT_SIZE_CLASS } + attributes: { 'class': className } }); return this.focus(); }; proto.setTextColour = function ( colour ) { + var className = this._config.classNames.colour; this.changeFormat( colour ? { tag: 'SPAN', attributes: { - 'class': COLOUR_CLASS, + 'class': className, style: 'color:' + colour } } : null, { tag: 'SPAN', - attributes: { 'class': COLOUR_CLASS } + attributes: { 'class': className } }); return this.focus(); }; proto.setHighlightColour = function ( colour ) { + var className = this._config.classNames.highlight; this.changeFormat( colour ? { tag: 'SPAN', attributes: { - 'class': HIGHLIGHT_CLASS, + 'class': className, style: 'background-color:' + colour } } : colour, { tag: 'SPAN', - attributes: { 'class': HIGHLIGHT_CLASS } + attributes: { 'class': className } }); return this.focus(); }; diff --git a/source/Node.js b/source/Node.js index 222fc5c..2cefc43 100644 --- a/source/Node.js +++ b/source/Node.js @@ -129,11 +129,11 @@ function isOrContains ( parent, node ) { return false; } -function getPath ( node, root ) { +function getPath ( node, root, config ) { var path = ''; - var id, className, classNames, dir; + var id, className, classNames, dir, styleNames; if ( node && node !== root ) { - path = getPath( node.parentNode, root ); + path = getPath( node.parentNode, root, config ); if ( node.nodeType === ELEMENT_NODE ) { path += ( path ? '>' : '' ) + node.nodeName; if ( id = node.id ) { @@ -149,19 +149,20 @@ function getPath ( node, root ) { path += '[dir=' + dir + ']'; } if ( classNames ) { - if ( indexOf.call( classNames, HIGHLIGHT_CLASS ) > -1 ) { + styleNames = config.classNames; + if ( indexOf.call( classNames, styleNames.highlight ) > -1 ) { path += '[backgroundColor=' + node.style.backgroundColor.replace( / /g,'' ) + ']'; } - if ( indexOf.call( classNames, COLOUR_CLASS ) > -1 ) { + if ( indexOf.call( classNames, styleNames.colour ) > -1 ) { path += '[color=' + node.style.color.replace( / /g,'' ) + ']'; } - if ( indexOf.call( classNames, FONT_FAMILY_CLASS ) > -1 ) { + if ( indexOf.call( classNames, styleNames.fontFamily ) > -1 ) { path += '[fontFamily=' + node.style.fontFamily.replace( / /g,'' ) + ']'; } - if ( indexOf.call( classNames, FONT_SIZE_CLASS ) > -1 ) { + if ( indexOf.call( classNames, styleNames.fontSize ) > -1 ) { path += '[fontSize=' + node.style.fontSize + ']'; } }