diff --git a/build/squire-raw.js b/build/squire-raw.js
index ac3ca72..8984e28 100644
--- a/build/squire-raw.js
+++ b/build/squire-raw.js
@@ -17,6 +17,11 @@ var START_TO_END = 1; // Range.START_TO_END
var END_TO_END = 2; // Range.END_TO_END
var END_TO_START = 3; // Range.END_TO_START
+var HIGHLIGHT_CLASS = 'highlight';
+var COLOUR_CLASS = 'colour';
+var FONT_FAMILY_CLASS = 'font';
+var FONT_SIZE_CLASS = 'size';
+
var ZWS = '\u200B';
var win = doc.defaultView;
@@ -26,11 +31,14 @@ var ua = navigator.userAgent;
var isIOS = /iP(?:ad|hone|od)/.test( ua );
var isMac = /Mac OS X/.test( ua );
+var isAndroid = /Android/.test( ua );
+
var isGecko = /Gecko\//.test( ua );
var isIElt11 = /Trident\/[456]\./.test( ua );
var isPresto = !!win.opera;
var isEdge = /Edge\//.test( ua );
var isWebKit = !isEdge && /WebKit\//.test( ua );
+var isIE = /Trident\/[4567]\./.test( ua );
var ctrlKey = isMac ? 'meta-' : 'ctrl-';
@@ -171,7 +179,7 @@ TreeWalker.prototype.previousPONode = function () {
}
};
-var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|U|VAR|WBR)$/;
+var inlineNodeNames = /^(?:#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)$/;
var leafNodeNames = {
BR: 1,
@@ -284,6 +292,23 @@ function getPath ( node, root ) {
if ( dir = node.dir ) {
path += '[dir=' + dir + ']';
}
+ if ( classNames ) {
+ if ( indexOf.call( classNames, HIGHLIGHT_CLASS ) > -1 ) {
+ path += '[backgroundColor=' +
+ node.style.backgroundColor.replace( / /g,'' ) + ']';
+ }
+ if ( indexOf.call( classNames, COLOUR_CLASS ) > -1 ) {
+ path += '[color=' +
+ node.style.color.replace( / /g,'' ) + ']';
+ }
+ if ( indexOf.call( classNames, FONT_FAMILY_CLASS ) > -1 ) {
+ path += '[fontFamily=' +
+ node.style.fontFamily.replace( / /g,'' ) + ']';
+ }
+ if ( indexOf.call( classNames, FONT_SIZE_CLASS ) > -1 ) {
+ path += '[fontSize=' + node.style.fontSize + ']';
+ }
+ }
}
}
return path;
@@ -522,10 +547,7 @@ function split ( node, offset, stopNode, root ) {
return offset;
}
-function mergeInlines ( node, range ) {
- if ( node.nodeType !== ELEMENT_NODE ) {
- return;
- }
+function _mergeInlines ( node, fakeRange ) {
var children = node.childNodes,
l = children.length,
frags = [],
@@ -535,30 +557,30 @@ function mergeInlines ( node, range ) {
prev = l && children[ l - 1 ];
if ( l && isInline( child ) && areAlike( child, prev ) &&
!leafNodeNames[ child.nodeName ] ) {
- if ( range.startContainer === child ) {
- range.startContainer = prev;
- range.startOffset += getLength( prev );
+ if ( fakeRange.startContainer === child ) {
+ fakeRange.startContainer = prev;
+ fakeRange.startOffset += getLength( prev );
}
- if ( range.endContainer === child ) {
- range.endContainer = prev;
- range.endOffset += getLength( prev );
+ if ( fakeRange.endContainer === child ) {
+ fakeRange.endContainer = prev;
+ fakeRange.endOffset += getLength( prev );
}
- if ( range.startContainer === node ) {
- if ( range.startOffset > l ) {
- range.startOffset -= 1;
+ if ( fakeRange.startContainer === node ) {
+ if ( fakeRange.startOffset > l ) {
+ fakeRange.startOffset -= 1;
}
- else if ( range.startOffset === l ) {
- range.startContainer = prev;
- range.startOffset = getLength( prev );
+ else if ( fakeRange.startOffset === l ) {
+ fakeRange.startContainer = prev;
+ fakeRange.startOffset = getLength( prev );
}
}
- if ( range.endContainer === node ) {
- if ( range.endOffset > l ) {
- range.endOffset -= 1;
+ if ( fakeRange.endContainer === node ) {
+ if ( fakeRange.endOffset > l ) {
+ fakeRange.endOffset -= 1;
}
- else if ( range.endOffset === l ) {
- range.endContainer = prev;
- range.endOffset = getLength( prev );
+ else if ( fakeRange.endOffset === l ) {
+ fakeRange.endContainer = prev;
+ fakeRange.endOffset = getLength( prev );
}
}
detach( child );
@@ -574,14 +596,31 @@ function mergeInlines ( node, range ) {
while ( len-- ) {
child.appendChild( frags.pop() );
}
- mergeInlines( child, range );
+ _mergeInlines( child, fakeRange );
}
}
}
+function mergeInlines ( node, range ) {
+ if ( node.nodeType === TEXT_NODE ) {
+ node = node.parentNode;
+ }
+ if ( node.nodeType === ELEMENT_NODE ) {
+ var fakeRange = {
+ startContainer: range.startContainer,
+ startOffset: range.startOffset,
+ endContainer: range.endContainer,
+ endOffset: range.endOffset
+ };
+ _mergeInlines( node, fakeRange );
+ range.setStart( fakeRange.startContainer, fakeRange.startOffset );
+ range.setEnd( fakeRange.endContainer, fakeRange.endOffset );
+ }
+}
+
function mergeWithBlock ( block, next, range ) {
var container = next,
- last, offset, _range;
+ last, offset;
while ( container.parentNode.childNodes.length === 1 ) {
container = container.parentNode;
}
@@ -596,18 +635,11 @@ function mergeWithBlock ( block, next, range ) {
offset -= 1;
}
- _range = {
- startContainer: block,
- startOffset: offset,
- endContainer: block,
- endOffset: offset
- };
-
block.appendChild( empty( next ) );
- mergeInlines( block, _range );
- range.setStart( _range.startContainer, _range.startOffset );
+ range.setStart( block, offset );
range.collapse( true );
+ mergeInlines( block, range );
// Opera inserts a BR if you delete the last piece of text
// in a block-level element. Unfortunately, it then gets
@@ -862,6 +894,10 @@ var insertTreeFragmentIntoRange = function ( range, frag, root ) {
if ( allInline ) {
// If inline, just insert at the current position.
insertNodeInRange( range, frag );
+ if ( range.startContainer !== range.endContainer ) {
+ mergeInlines( range.endContainer, range );
+ }
+ mergeInlines( range.startContainer, range );
range.collapse( false );
} else {
// Otherwise...
@@ -1300,7 +1336,7 @@ var afterDelete = function ( self, range ) {
node = parent;
parent = node.parentNode;
}
- // If focussed in empty inline element
+ // If focused in empty inline element
if ( node !== parent ) {
// Move focus to just before empty inline(s)
range.setStart( parent,
@@ -1622,6 +1658,13 @@ var keyHandlers = {
!node.nextSibling && range.endOffset === getLength( node ) ) {
range.setStartAfter( parent );
}
+ // Delete the selection if not collapsed
+ else if ( !range.collapsed ) {
+ deleteContentsOfRange( range, self._root );
+ self._ensureBottomLine();
+ self.setSelection( range );
+ self._updatePath( range, true );
+ }
self.setSelection( range );
},
@@ -1690,12 +1733,12 @@ var fontSizes = {
7: 48
};
-var spanToSemantic = {
+var styleToSemantic = {
backgroundColor: {
regexp: notWS,
replace: function ( doc, colour ) {
return createElement( doc, 'SPAN', {
- 'class': 'highlight',
+ 'class': HIGHLIGHT_CLASS,
style: 'background-color:' + colour
});
}
@@ -1704,7 +1747,7 @@ var spanToSemantic = {
regexp: notWS,
replace: function ( doc, colour ) {
return createElement( doc, 'SPAN', {
- 'class': 'colour',
+ 'class': COLOUR_CLASS,
style: 'color:' + colour
});
}
@@ -1725,7 +1768,7 @@ var spanToSemantic = {
regexp: notWS,
replace: function ( doc, family ) {
return createElement( doc, 'SPAN', {
- 'class': 'font',
+ 'class': FONT_FAMILY_CLASS,
style: 'font-family:' + family
});
}
@@ -1734,10 +1777,16 @@ var spanToSemantic = {
regexp: notWS,
replace: function ( doc, size ) {
return createElement( doc, 'SPAN', {
- 'class': 'size',
+ 'class': FONT_SIZE_CLASS,
style: 'font-size:' + size
});
}
+ },
+ textDecoration: {
+ regexp: /^underline/i,
+ replace: function ( doc ) {
+ return createElement( doc, 'U' );
+ }
}
};
@@ -1750,36 +1799,45 @@ var replaceWithTag = function ( tag ) {
};
};
-var stylesRewriters = {
- SPAN: function ( span, parent ) {
- var style = span.style,
- doc = span.ownerDocument,
- attr, converter, css, newTreeBottom, newTreeTop, el;
+var replaceStyles = function ( node, parent ) {
+ var style = node.style;
+ var doc = node.ownerDocument;
+ var attr, converter, css, newTreeBottom, newTreeTop, el;
- for ( attr in spanToSemantic ) {
- converter = spanToSemantic[ attr ];
- css = style[ attr ];
- if ( css && converter.regexp.test( css ) ) {
- el = converter.replace( doc, css );
- if ( newTreeBottom ) {
- newTreeBottom.appendChild( el );
- }
- newTreeBottom = el;
- if ( !newTreeTop ) {
- newTreeTop = el;
- }
+ for ( attr in styleToSemantic ) {
+ converter = styleToSemantic[ attr ];
+ css = style[ attr ];
+ if ( css && converter.regexp.test( css ) ) {
+ el = converter.replace( doc, css );
+ if ( !newTreeTop ) {
+ newTreeTop = el;
}
+ if ( newTreeBottom ) {
+ newTreeBottom.appendChild( el );
+ }
+ newTreeBottom = el;
+ node.style[ attr ] = '';
}
+ }
- if ( newTreeTop ) {
- newTreeBottom.appendChild( empty( span ) );
- parent.replaceChild( newTreeTop, span );
+ if ( newTreeTop ) {
+ newTreeBottom.appendChild( empty( node ) );
+ if ( node.nodeName === 'SPAN' ) {
+ parent.replaceChild( newTreeTop, node );
+ } else {
+ node.appendChild( newTreeTop );
}
+ }
- return newTreeBottom || span;
- },
+ return newTreeBottom || node;
+};
+
+var stylesRewriters = {
+ P: replaceStyles,
+ SPAN: replaceStyles,
STRONG: replaceWithTag( 'B' ),
EM: replaceWithTag( 'I' ),
+ INS: replaceWithTag( 'U' ),
STRIKE: replaceWithTag( 'S' ),
FONT: function ( node, parent ) {
var face = node.face,
@@ -2059,12 +2117,32 @@ var onCopy = function ( event ) {
var clipboardData = event.clipboardData;
var range = this.getSelection();
var node = this.createElement( 'div' );
+ var root = this._root;
+ var startBlock, contents, parent, newContents;
// Edge only seems to support setting plain text as of 2016-03-11.
// Mobile Safari flat out doesn't work:
// https://bugs.webkit.org/show_bug.cgi?id=143776
if ( !isEdge && !isIOS && clipboardData ) {
- node.appendChild( range.cloneContents() );
+ range = range.cloneRange();
+ startBlock = getStartBlockOfRange( range, root );
+ if ( startBlock === getEndBlockOfRange( range, root ) ) {
+ // Copy all inline formatting, but that's it.
+ moveRangeBoundariesDownTree( range );
+ moveRangeBoundariesUpTree( range, startBlock );
+ contents = range.cloneContents();
+ } else {
+ moveRangeBoundariesUpTree( range, root );
+ contents = range.cloneContents();
+ parent = range.commonAncestorContainer;
+ while ( parent && parent !== root ) {
+ newContents = parent.cloneNode( false );
+ newContents.appendChild( contents );
+ contents = newContents;
+ parent = parent.parentNode;
+ }
+ }
+ node.appendChild( contents );
clipboardData.setData( 'text/html', node.innerHTML );
clipboardData.setData( 'text/plain',
node.innerText || node.textContent );
@@ -2072,14 +2150,21 @@ var onCopy = function ( event ) {
}
};
+// Need to monitor for shift key like this, as event.shiftKey is not available
+// in paste event.
+function monitorShiftKey ( event ) {
+ this.isShiftDown = event.shiftKey;
+}
+
var onPaste = function ( event ) {
- var clipboardData = event.clipboardData,
- items = clipboardData && clipboardData.items,
- fireDrop = false,
- hasImage = false,
- plainItem = null,
- self = this,
- l, item, type, types, data;
+ var clipboardData = event.clipboardData;
+ var items = clipboardData && clipboardData.items;
+ var choosePlain = this.isShiftDown;
+ var fireDrop = false;
+ var hasImage = false;
+ var plainItem = null;
+ var self = this;
+ var l, item, type, types, data;
// Current HTML5 Clipboard interface
// ---------------------------------
@@ -2092,7 +2177,7 @@ var onPaste = function ( event ) {
while ( l-- ) {
item = items[l];
type = item.type;
- if ( type === 'text/html' ) {
+ if ( !choosePlain && type === 'text/html' ) {
/*jshint loopfunc: true */
item.getAsString( function ( html ) {
self.insertHTML( html, true );
@@ -2103,7 +2188,7 @@ var onPaste = function ( event ) {
if ( type === 'text/plain' ) {
plainItem = item;
}
- if ( /^image\/.*/.test( type ) ) {
+ if ( !choosePlain && /^image\/.*/.test( type ) ) {
hasImage = true;
}
}
@@ -2155,7 +2240,7 @@ var onPaste = function ( event ) {
// insert plain text instead. On iOS, Facebook (and possibly other
// apps?) copy links as type text/uri-list, but also insert a **blank**
// text/plain item onto the clipboard. Why? Who knows.
- if (( data = clipboardData.getData( 'text/html' ) )) {
+ if ( !choosePlain && ( data = clipboardData.getData( 'text/html' ) ) ) {
this.insertHTML( data, true );
} else if (
( data = clipboardData.getData( 'text/plain' ) ) ||
@@ -2267,16 +2352,20 @@ function getSquireInstance ( doc ) {
return null;
}
-function mergeObjects ( base, extras ) {
+function mergeObjects ( base, extras, mayOverride ) {
var prop, value;
if ( !base ) {
base = {};
}
- for ( prop in extras ) {
- value = extras[ prop ];
- base[ prop ] = ( value && value.constructor === Object ) ?
- mergeObjects( base[ prop ], value ) :
- value;
+ if ( extras ) {
+ for ( prop in extras ) {
+ if ( mayOverride || !( prop in base ) ) {
+ value = extras[ prop ];
+ base[ prop ] = ( value && value.constructor === Object ) ?
+ mergeObjects( base[ prop ], value, mayOverride ) :
+ value;
+ }
+ }
}
return base;
}
@@ -2295,6 +2384,7 @@ function Squire ( root, config ) {
this._events = {};
+ this._isFocused = false;
this._lastSelection = null;
// IE loses selection state of iframe on blur, so make sure we
@@ -2308,6 +2398,7 @@ function Squire ( root, config ) {
this._lastAnchorNode = null;
this._lastFocusNode = null;
this._path = '';
+ this._willUpdatePath = false;
if ( 'onselectionchange' in doc ) {
this.addEventListener( 'selectionchange', this._updatePathOnEvent );
@@ -2336,13 +2427,11 @@ function Squire ( root, config ) {
this.addEventListener( 'keyup', this._keyUpDetectChange );
}
- // On blur, restore focus except if there is any change to the content, or
- // the user taps or clicks to focus a specific point. Can't actually use
- // click event because focus happens before click, so use
- // mousedown/touchstart
+ // On blur, restore focus except if the user taps or clicks to focus a
+ // specific point. Can't actually use click event because focus happens
+ // before click, so use mousedown/touchstart
this._restoreSelection = false;
this.addEventListener( 'blur', enableRestoreSelection );
- this.addEventListener( 'input', disableRestoreSelection );
this.addEventListener( 'mousedown', disableRestoreSelection );
this.addEventListener( 'touchstart', disableRestoreSelection );
this.addEventListener( 'focus', restoreSelection );
@@ -2352,6 +2441,8 @@ function Squire ( root, config ) {
this._awaitingPaste = false;
this.addEventListener( isIElt11 ? 'beforecut' : 'cut', onCut );
this.addEventListener( 'copy', onCopy );
+ this.addEventListener( 'keydown', monitorShiftKey );
+ this.addEventListener( 'keyup', monitorShiftKey );
this.addEventListener( isIElt11 ? 'beforepaste' : 'paste', onPaste );
this.addEventListener( 'drop', onDrop );
@@ -2420,8 +2511,13 @@ proto.setConfig = function ( config ) {
ol: null,
li: null,
a: null
+ },
+ leafNodeNames: leafNodeNames,
+ undo: {
+ documentSizeThreshold: -1, // -1 means no threshold
+ undoLimit: -1 // -1 means no limit
}
- }, config );
+ }, config, true );
// Users may specify block tag in lower case
config.blockTag = config.blockTag.toUpperCase();
@@ -2483,8 +2579,26 @@ var customEvents = {
};
proto.fireEvent = function ( type, event ) {
- var handlers = this._events[ type ],
- l, obj;
+ var handlers = this._events[ type ];
+ var isFocused, l, obj;
+ // UI code, especially modal views, may be monitoring for focus events and
+ // immediately removing focus. In certain conditions, this can cause the
+ // focus event to fire after the blur event, which can cause an infinite
+ // loop. So we detect whether we're actually focused/blurred before firing.
+ if ( /^(?:focus|blur)/.test( type ) ) {
+ isFocused = isOrContains( this._root, this._doc.activeElement );
+ if ( type === 'focus' ) {
+ if ( !isFocused || this._isFocused ) {
+ return this;
+ }
+ this._isFocused = true;
+ } else {
+ if ( isFocused || !this._isFocused ) {
+ return this;
+ }
+ this._isFocused = false;
+ }
+ }
if ( handlers ) {
if ( !event ) {
event = {};
@@ -2516,6 +2630,7 @@ proto.destroy = function () {
var l = instances.length;
var events = this._events;
var type;
+
for ( type in events ) {
this.removeEventListener( type );
}
@@ -2527,6 +2642,11 @@ proto.destroy = function () {
instances.splice( l, 1 );
}
}
+
+ // Destroy undo stack
+ this._undoIndex = -1;
+ this._undoStack = [];
+ this._undoStackLength = 0;
};
proto.handleEvent = function ( event ) {
@@ -2617,12 +2737,7 @@ proto.getCursorPosition = function ( range ) {
rect = node.getBoundingClientRect();
parent = node.parentNode;
parent.removeChild( node );
- mergeInlines( parent, {
- startContainer: range.startContainer,
- endContainer: range.endContainer,
- startOffset: range.startOffset,
- endOffset: range.endOffset
- });
+ mergeInlines( parent, range );
}
return rect;
};
@@ -2647,20 +2762,34 @@ var getWindowSelection = function ( self ) {
proto.setSelection = function ( range ) {
if ( range ) {
- // If we're setting selection, that automatically, and synchronously, // triggers a focus event. Don't want a reentrant call to setSelection.
- this._restoreSelection = false;
this._lastSelection = range;
- // iOS bug: if you don't focus the iframe before setting the
- // selection, you can end up in a state where you type but the input
- // doesn't get directed into the contenteditable area but is instead
- // lost in a black hole. Very strange.
- if ( isIOS ) {
- this._win.focus();
- }
- var sel = getWindowSelection( this );
- if ( sel ) {
- sel.removeAllRanges();
- sel.addRange( range );
+ // If we're setting selection, that automatically, and synchronously, // triggers a focus event. So just store the selection and mark it as
+ // needing restore on focus.
+ if ( !this._isFocused ) {
+ enableRestoreSelection.call( this );
+ } else if ( isAndroid && !this._restoreSelection ) {
+ // Android closes the keyboard on removeAllRanges() and doesn't
+ // open it again when addRange() is called, sigh.
+ // Since Android doesn't trigger a focus event in setSelection(),
+ // use a blur/focus dance to work around this by letting the
+ // selection be restored on focus.
+ // Need to check for !this._restoreSelection to avoid infinite loop
+ enableRestoreSelection.call( this );
+ this.blur();
+ this.focus();
+ } else {
+ // iOS bug: if you don't focus the iframe before setting the
+ // selection, you can end up in a state where you type but the input
+ // doesn't get directed into the contenteditable area but is instead
+ // lost in a black hole. Very strange.
+ if ( isIOS ) {
+ this._win.focus();
+ }
+ var sel = getWindowSelection( this );
+ if ( sel ) {
+ sel.removeAllRanges();
+ sel.addRange( range );
+ }
}
}
return this;
@@ -2758,13 +2887,18 @@ proto.getPath = function () {
// WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=15256
-var removeZWS = function ( root ) {
+// Walk down the tree starting at the root and remove any ZWS. If the node only
+// contained ZWS space then remove it too. We may want to keep one ZWS node at
+// the bottom of the tree so the block can be selected. Define that node as the
+// keepNode.
+var removeZWS = function ( root, keepNode ) {
var walker = new TreeWalker( root, SHOW_TEXT, function () {
return true;
}, false ),
parent, node, index;
while ( node = walker.nextNode() ) {
- while ( ( index = node.data.indexOf( ZWS ) ) > -1 ) {
+ while ( ( index = node.data.indexOf( ZWS ) ) > -1 &&
+ ( !keepNode || node.parentNode !== keepNode ) ) {
if ( node.length === 1 ) {
do {
parent = node.parentNode;
@@ -2813,19 +2947,39 @@ proto._updatePath = function ( range, force ) {
}
};
+// selectionchange is fired synchronously in IE when removing current selection
+// and when setting new selection; keyup/mouseup may have processing we want
+// to do first. Either way, send to next event loop.
proto._updatePathOnEvent = function () {
- this._updatePath( this.getSelection() );
+ var self = this;
+ if ( !self._willUpdatePath ) {
+ self._willUpdatePath = true;
+ setTimeout( function () {
+ self._willUpdatePath = false;
+ self._updatePath( self.getSelection() );
+ }, 0 );
+ }
};
// --- Focus ---
proto.focus = function () {
this._root.focus();
+
+ if ( isIE ) {
+ this.fireEvent( 'focus' );
+ }
+
return this;
};
proto.blur = function () {
this._root.blur();
+
+ if ( isIE ) {
+ this.fireEvent( 'blur' );
+ }
+
return this;
};
@@ -2871,38 +3025,31 @@ proto._getRangeAndRemoveBookmark = function ( range ) {
if ( start && end ) {
var startContainer = start.parentNode,
endContainer = end.parentNode,
- collapsed;
-
- var _range = {
- startContainer: startContainer,
- endContainer: endContainer,
- startOffset: indexOf.call( startContainer.childNodes, start ),
- endOffset: indexOf.call( endContainer.childNodes, end )
- };
+ startOffset = indexOf.call( startContainer.childNodes, start ),
+ endOffset = indexOf.call( endContainer.childNodes, end );
if ( startContainer === endContainer ) {
- _range.endOffset -= 1;
+ endOffset -= 1;
}
detach( start );
detach( end );
- // Merge any text nodes we split
- mergeInlines( startContainer, _range );
- if ( startContainer !== endContainer ) {
- mergeInlines( endContainer, _range );
- }
-
if ( !range ) {
range = this._doc.createRange();
}
- range.setStart( _range.startContainer, _range.startOffset );
- range.setEnd( _range.endContainer, _range.endOffset );
- collapsed = range.collapsed;
+ range.setStart( startContainer, startOffset );
+ range.setEnd( endContainer, endOffset );
+
+ // Merge any text nodes we split
+ mergeInlines( startContainer, range );
+ if ( startContainer !== endContainer ) {
+ mergeInlines( endContainer, range );
+ }
// If we didn't split a text node, we should move into any adjacent
// text node to current selection point
- if ( collapsed ) {
+ if ( range.collapsed ) {
startContainer = range.startContainer;
if ( startContainer.nodeType === TEXT_NODE ) {
endContainer = startContainer.childNodes[ range.startOffset ];
@@ -2959,19 +3106,37 @@ proto._recordUndoState = function ( range ) {
// Don't record if we're already in an undo state
if ( !this._isInUndoState ) {
// Advance pointer to new position
- var undoIndex = this._undoIndex += 1,
- undoStack = this._undoStack;
+ var undoIndex = this._undoIndex += 1;
+ var undoStack = this._undoStack;
+ var undoConfig = this._config.undo;
+ var undoThreshold = undoConfig.documentSizeThreshold;
+ var undoLimit = undoConfig.undoLimit;
+ var html;
// Truncate stack if longer (i.e. if has been previously undone)
if ( undoIndex < this._undoStackLength ) {
undoStack.length = this._undoStackLength = undoIndex;
}
- // Write out data
+ // Get data
if ( range ) {
this._saveRangeToBookmark( range );
}
- undoStack[ undoIndex ] = this._getHTML();
+ html = this._getHTML();
+
+ // If this document is above the configured size threshold,
+ // limit the number of saved undo states.
+ // Threshold is in bytes, JS uses 2 bytes per character
+ if ( undoThreshold > -1 && html.length * 2 > undoThreshold ) {
+ if ( undoLimit > -1 && undoIndex > undoLimit ) {
+ undoStack.splice( 0, undoIndex - undoLimit );
+ undoIndex = this._undoIndex = undoLimit;
+ this._undoStackLength = undoLimit;
+ }
+ }
+
+ // Save data
+ undoStack[ undoIndex ] = html;
this._undoStackLength += 1;
this._isInUndoState = true;
}
@@ -3141,13 +3306,21 @@ proto._addFormat = function ( tag, attributes, range ) {
// it round the range and focus it.
var root = this._root;
var el, walker, startContainer, endContainer, startOffset, endOffset,
- node, needsFormat;
+ node, needsFormat, block;
if ( range.collapsed ) {
el = fixCursor( this.createElement( tag, attributes ), root );
insertNodeInRange( range, el );
range.setStart( el.firstChild, el.firstChild.length );
range.collapse( true );
+
+ // Clean up any previous formats that may have been set on this block
+ // that are unused.
+ block = el;
+ while ( isInline( block ) ) {
+ block = block.parentNode;
+ }
+ removeZWS( block, el );
}
// Otherwise we find all the textnodes in the range (splitting
// partially selected nodes) and if they're not already formatted
@@ -3162,8 +3335,8 @@ proto._addFormat = function ( tag, attributes, range ) {
// to apply when the user types something in the block, which is
// presumably what was intended.
//
- // IMG tags are included because we may want to create a link around them,
- // and adding other styles is harmless.
+ // IMG tags are included because we may want to create a link around
+ // them, and adding other styles is harmless.
walker = new TreeWalker(
range.commonAncestorContainer,
SHOW_TEXT|SHOW_ELEMENT,
@@ -3342,15 +3515,7 @@ proto._removeFormat = function ( tag, attributes, range, partial ) {
if ( fixer ) {
range.collapse( false );
}
- var _range = {
- startContainer: range.startContainer,
- startOffset: range.startOffset,
- endContainer: range.endContainer,
- endOffset: range.endOffset
- };
- mergeInlines( root, _range );
- range.setStart( _range.startContainer, _range.startOffset );
- range.setEnd( _range.endContainer, _range.endOffset );
+ mergeInlines( root, range );
return range;
};
@@ -3358,7 +3523,7 @@ proto._removeFormat = function ( tag, attributes, range, partial ) {
proto.changeFormat = function ( add, remove, range, partial ) {
// Normalise the arguments and get selection
if ( !range && !( range = this.getSelection() ) ) {
- return;
+ return this;
}
// Save undo checkpoint
@@ -3769,6 +3934,7 @@ proto.setHTML = function ( html ) {
// anything calls getSelection before first focus, we have a range
// to return.
this._lastSelection = range;
+ enableRestoreSelection.call( this );
this._updatePath( range, true );
return this;
@@ -3820,7 +3986,7 @@ proto.insertElement = function ( el, range ) {
proto.insertImage = function ( src, attributes ) {
var img = this.createElement( 'IMG', mergeObjects({
src: src
- }, attributes ));
+ }, attributes, true ));
this.insertElement( img );
return img;
};
@@ -3851,7 +4017,7 @@ var addLinks = function ( frag, root, self ) {
match[1] :
'http://' + match[1] :
'mailto:' + match[2]
- }, defaultAttributes ));
+ }, defaultAttributes, false ));
child.textContent = data.slice( index, endIndex );
parent.insertBefore( child, node );
node.data = data = data.slice( endIndex );
@@ -3864,27 +4030,35 @@ var addLinks = function ( frag, root, self ) {
// by the html being inserted.
proto.insertHTML = function ( html, isPaste ) {
var range = this.getSelection();
- var frag = this._doc.createDocumentFragment();
- var div = this.createElement( 'DIV' );
+ var doc = this._doc;
var startFragmentIndex, endFragmentIndex;
- var root, node, event;
+ var div, frag, root, node, event;
// Edge doesn't just copy the fragment, but includes the surrounding guff
- // including the full
of the page. Need to strip this out. In the
- // future should probably run all pastes through DOMPurify, but this will
- // do for now
- if ( isPaste ) {
- startFragmentIndex = html.indexOf( '' );
- endFragmentIndex = html.lastIndexOf( '' );
- if ( startFragmentIndex > -1 && endFragmentIndex > -1 ) {
- html = html.slice( startFragmentIndex + 20, endFragmentIndex );
+ // including the full of the page. Need to strip this out. If
+ // available use DOMPurify to parse and sanitise.
+ if ( typeof DOMPurify !== 'undefined' && DOMPurify.isSupported ) {
+ frag = DOMPurify.sanitize( html, {
+ WHOLE_DOCUMENT: false,
+ RETURN_DOM: true,
+ RETURN_DOM_FRAGMENT: true
+ });
+ frag = doc.importNode( frag, true );
+ } else {
+ if ( isPaste ) {
+ startFragmentIndex = html.indexOf( '' );
+ endFragmentIndex = html.lastIndexOf( '' );
+ if ( startFragmentIndex > -1 && endFragmentIndex > -1 ) {
+ html = html.slice( startFragmentIndex + 20, endFragmentIndex );
+ }
}
+ // Parse HTML into DOM tree
+ div = this.createElement( 'DIV' );
+ div.innerHTML = html;
+ frag = doc.createDocumentFragment();
+ frag.appendChild( empty( div ) );
}
- // Parse HTML into DOM tree
- div.innerHTML = html;
- frag.appendChild( empty( div ) );
-
// Record undo checkpoint
this.saveUndoState( range );
@@ -3924,6 +4098,10 @@ proto.insertHTML = function ( html, isPaste ) {
this.setSelection( range );
this._updatePath( range, true );
+ // Safari sometimes loses focus after paste. Weird.
+ if ( isPaste ) {
+ this.focus();
+ }
} catch ( error ) {
this.didError( error );
}
@@ -4012,12 +4190,13 @@ proto.makeLink = function ( url, attributes ) {
this._doc.createTextNode( url.slice( protocolEnd ) )
);
}
-
- if ( !attributes ) {
- attributes = {};
- }
- mergeObjects( attributes, this._config.tagAttributes.a );
- attributes.href = url;
+ attributes = mergeObjects(
+ mergeObjects({
+ href: url
+ }, attributes, true ),
+ this._config.tagAttributes.a,
+ false
+ );
this.changeFormat({
tag: 'A',
@@ -4035,27 +4214,27 @@ proto.removeLink = function () {
};
proto.setFontFace = function ( name ) {
- this.changeFormat({
+ this.changeFormat( name ? {
tag: 'SPAN',
attributes: {
'class': 'font',
style: 'font-family: ' + name + ', sans-serif;'
}
- }, {
+ } : null, {
tag: 'SPAN',
attributes: { 'class': 'font' }
});
return this.focus();
};
proto.setFontSize = function ( size ) {
- this.changeFormat({
+ this.changeFormat( size ? {
tag: 'SPAN',
attributes: {
'class': 'size',
style: 'font-size: ' +
( typeof size === 'number' ? size + 'px' : size )
}
- }, {
+ } : null, {
tag: 'SPAN',
attributes: { 'class': 'size' }
});
@@ -4063,13 +4242,13 @@ proto.setFontSize = function ( size ) {
};
proto.setTextColour = function ( colour ) {
- this.changeFormat({
+ this.changeFormat( colour ? {
tag: 'SPAN',
attributes: {
'class': 'colour',
style: 'color:' + colour
}
- }, {
+ } : null, {
tag: 'SPAN',
attributes: { 'class': 'colour' }
});
@@ -4077,13 +4256,13 @@ proto.setTextColour = function ( colour ) {
};
proto.setHighlightColour = function ( colour ) {
- this.changeFormat({
+ this.changeFormat( colour ? {
tag: 'SPAN',
attributes: {
'class': 'highlight',
style: 'background-color:' + colour
}
- }, {
+ } : colour, {
tag: 'SPAN',
attributes: { 'class': 'highlight' }
});
@@ -4170,7 +4349,7 @@ proto.removeAllFormatting = function ( range ) {
var cleanNodes = doc.createDocumentFragment();
var nodeAfterSplit = split( endContainer, endOffset, stopNode, root );
var nodeInSplit = split( startContainer, startOffset, stopNode, root );
- var nextNode, _range, childNodes;
+ var nextNode, childNodes;
// Then replace contents in split with a cleaned version of the same:
// blocks become default blocks, text and leaf nodes survive, everything
@@ -4197,15 +4376,9 @@ proto.removeAllFormatting = function ( range ) {
}
// Merge text nodes at edges, if possible
- _range = {
- startContainer: stopNode,
- startOffset: startOffset,
- endContainer: stopNode,
- endOffset: endOffset
- };
- mergeInlines( stopNode, _range );
- range.setStart( _range.startContainer, _range.startOffset );
- range.setEnd( _range.endContainer, _range.endOffset );
+ range.setStart( stopNode, startOffset );
+ range.setEnd( stopNode, endOffset );
+ mergeInlines( stopNode, range );
// And move back down the tree
moveRangeBoundariesDownTree( range );
@@ -4226,6 +4399,32 @@ proto.removeList = command( 'modifyBlocks', removeList );
proto.increaseListLevel = command( 'modifyBlocks', increaseListLevel );
proto.decreaseListLevel = command( 'modifyBlocks', decreaseListLevel );
+// Range.js exports
+Squire.getNodeBefore = getNodeBefore;
+Squire.getNodeAfter = getNodeAfter;
+Squire.insertNodeInRange = insertNodeInRange;
+Squire.extractContentsOfRange = extractContentsOfRange;
+Squire.deleteContentsOfRange = deleteContentsOfRange;
+Squire.insertTreeFragmentIntoRange = insertTreeFragmentIntoRange;
+Squire.isNodeContainedInRange = isNodeContainedInRange;
+Squire.moveRangeBoundariesDownTree = moveRangeBoundariesDownTree;
+Squire.moveRangeBoundariesUpTree = moveRangeBoundariesUpTree;
+Squire.getStartBlockOfRange = getStartBlockOfRange;
+Squire.getEndBlockOfRange = getEndBlockOfRange;
+Squire.contentWalker = contentWalker;
+Squire.rangeDoesStartAtBlockBoundary = rangeDoesStartAtBlockBoundary;
+Squire.rangeDoesEndAtBlockBoundary = rangeDoesEndAtBlockBoundary;
+Squire.expandRangeToBlockBoundaries = expandRangeToBlockBoundaries;
+
+// Clipboard.js exports
+Squire.onPaste = onPaste;
+
+// Editor.js exports
+Squire.addLinks = addLinks;
+Squire.splitBlock = splitBlock;
+Squire.startSelectionId = startSelectionId;
+Squire.endSelectionId = endSelectionId;
+
if ( typeof exports === 'object' ) {
module.exports = Squire;
} else if ( typeof define === 'function' && define.amd ) {
diff --git a/build/squire.js b/build/squire.js
index 6431b79..47b7dbe 100644
--- a/build/squire.js
+++ b/build/squire.js
@@ -1,2 +1,2 @@
-!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(e){return e.nodeType===P&&!!ct[e.nodeName]}function i(e){return lt.test(e.nodeName)}function a(e){var t=e.nodeType;return(t===P||t===F)&&!i(e)&&r(e.childNodes,i)}function s(e){var t=e.nodeType;return!(t!==P&&t!==F||i(e)||a(e))}function d(e,t){var r=new n(t,M,a);return r.currentNode=e,r}function l(e,t){return e=d(e,t).previousNode(),e!==t?e:null}function c(e,t){return e=d(e,t).nextNode(),e!==t?e:null}function h(e,t){return!o(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&"A"!==e.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function f(e,t,n){if(e.nodeName!==t)return!1;for(var r in n)if(e.getAttribute(r)!==n[r])return!1;return!0}function u(e,t,n,r){for(;e&&e!==t;){if(f(e,n,r))return e;e=e.parentNode}return null}function p(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function g(e,t){var n,r,o,i,a="";return e&&e!==t&&(a=g(e.parentNode,t),e.nodeType===P&&(a+=(a?">":"")+e.nodeName,(n=e.id)&&(a+="#"+n),(r=e.className.trim())&&(o=r.split(/\s\s*/),o.sort(),a+=".",a+=o.join(".")),(i=e.dir)&&(a+="[dir="+i+"]"))),a}function m(e){var t=e.nodeType;return t===P?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function _(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=k(a).createDefaultBlock(),r?e.replaceChild(n,r):e.appendChild(n),e=n,n=null)),e.nodeType===I)return s;if(i(e)){for(r=e.firstChild;rt&&r&&r.nodeType===I&&!r.data;)e.removeChild(r),r=e.firstChild;r||(rt?(n=a.createTextNode(Z),k(a)._didAddZWS()):n=a.createTextNode(""))}else if(nt){for(;e.nodeType!==I&&!o(e);){if(r=e.firstChild,!r){n=a.createTextNode("");break}e=r}e.nodeType===I?/^ +$/.test(e.data)&&(e.data=""):o(e)&&e.parentNode.insertBefore(a.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=S(a,"BR");(r=e.lastElementChild)&&!i(r);)e=r;if(n)try{e.appendChild(n)}catch(d){k(a).didError({name:"Squire: fixCursor – "+d,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return s}function y(e,t){var n,r,o,a,d=e.childNodes,l=e.ownerDocument,c=null,h=k(l)._config;for(n=0,r=d.length;r>n;n+=1)o=d[n],a="BR"===o.nodeName,!a&&i(o)?(c||(c=S(l,h.blockTag,h.blockAttributes)),c.appendChild(o),n-=1,r-=1):(a||c)&&(c||(c=S(l,h.blockTag,h.blockAttributes)),_(c,t),a?e.replaceChild(c,o):(e.insertBefore(c,o),n+=1,r+=1),c=null),s(o)&&y(o,t);return c&&e.appendChild(_(c,t)),e}function T(e,t,n,r){var o,i,a,s=e.nodeType;if(s===I&&e!==n)return T(e.parentNode,e.splitText(t),n,r);if(s===P){if("number"==typeof t&&(t=ts?t.startOffset-=1:t.startOffset===s&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=r,t.endOffset=m(r))),v(n),n.nodeType===I?r.appendData(n.data):d.push(N(n));else if(n.nodeType===P){for(o=d.length;o--;)n.appendChild(d.pop());b(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(a),o=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),o-=1),i={startContainer:e,startOffset:o,endContainer:e,endOffset:o},e.appendChild(N(t)),b(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),X&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function x(e,t){var n,r,o=e.previousSibling,i=e.firstChild,a=e.ownerDocument,d="LI"===e.nodeName;if(!d||i&&/^[OU]L$/.test(i.nodeName))if(o&&h(o,e)){if(!s(o)){if(!d)return;r=S(a,"DIV"),r.appendChild(N(o)),o.appendChild(r)}v(e),n=!s(e),o.appendChild(N(e)),n&&y(o,t),i&&x(i,t)}else d&&(o=S(a,"DIV"),e.insertBefore(o,i),_(o,t))}function k(e){for(var t,n=Qt.length;n--;)if(t=Qt[n],t._doc===e)return t;return null}function O(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?O(e[n],r):r;return e}function L(e,t){e.nodeType===w&&(e=e.body);var n,r=e.ownerDocument,o=r.defaultView;this._win=o,this._doc=r,this._root=e,this._events={},this._lastSelection=null,ot&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="","onselectionchange"in r?this.addEventListener("selectionchange",this._updatePathOnEvent):(this.addEventListener("keyup",this._updatePathOnEvent),this.addEventListener("mouseup",this._updatePathOnEvent)),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,this._ignoreAllChanges=!1,it?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._restoreSelection=!1,this.addEventListener("blur",B),this.addEventListener("input",A),this.addEventListener("mousedown",A),this.addEventListener("touchstart",A),this.addEventListener("focus",D),this._awaitingPaste=!1,this.addEventListener(Y?"beforecut":"cut",Kt),this.addEventListener("copy",Zt),this.addEventListener(Y?"beforepaste":"paste",Gt),this.addEventListener("drop",jt),this.addEventListener(X?"keypress":"keydown",kt),this._keyHandlers=Object.create(At),this.setConfig(t),Y&&(o.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,r=this.parentNode,o=this.length-e;return n?r.insertBefore(t,n):r.appendChild(t),o&&this.deleteData(e,o),t}),e.setAttribute("contenteditable","true");try{r.execCommand("enableObjectResizing",!1,"false"),r.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}Qt.push(this),this.setHTML("")}function B(){this._restoreSelection=!0}function A(){this._restoreSelection=!1}function D(){this._restoreSelection&&this.setSelection(this._lastSelection)}function R(e,t,n){var r,o;for(r=t.firstChild;r;r=o){if(o=r.nextSibling,i(r)){if(r.nodeType===I||"BR"===r.nodeName||"IMG"===r.nodeName){n.appendChild(r);continue}}else if(a(r)){n.appendChild(e.createDefaultBlock([R(e,r,e._doc.createDocumentFragment())]));continue}R(e,r,n)}return n}var U=2,P=1,I=3,w=9,F=11,M=1,H=4,W=0,z=1,q=2,K=3,Z="",G=e.defaultView,j=navigator.userAgent,Q=/iP(?:ad|hone|od)/.test(j),V=/Mac OS X/.test(j),$=/Gecko\//.test(j),Y=/Trident\/[456]\./.test(j),X=!!G.opera,J=/Edge\//.test(j),et=!J&&/WebKit\//.test(j),tt=V?"meta-":"ctrl-",nt=Y||X,rt=Y||et,ot=Y,it="undefined"!=typeof MutationObserver,at=/[^ \t\r\n]/,st=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var dt={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)e=t.previousSibling,e||(t=t.parentNode);if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var lt=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|U|VAR|WBR)$/,ct={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},ht=function(e,t){for(var n=e.childNodes;t&&e.nodeType===P;)e=n[t-1],n=e.childNodes,t=n.length;return e},ft=function(e,t){if(e.nodeType===P){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(z,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(W,r)<1,s=e.compareBoundaryPoints(q,r)>-1;return a&&s},Ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,i=e.endContainer,a=e.endOffset;n.nodeType!==I&&(t=n.childNodes[r],t&&!o(t));)n=t,r=0;if(a)for(;i.nodeType!==I&&(t=i.childNodes[a-1],t&&!o(t));)i=t,a=m(i);else for(;i.nodeType!==I&&(t=i.firstChild,t&&!o(t));)i=t;e.collapsed?(e.setStart(i,a),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(i,a))},Nt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=st.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=st.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},St=function(e,t){var n,r=e.startContainer;return i(r)?n=l(r,t):a(r)?n=r:(n=ht(r,e.startOffset),n=c(n,t)),n&&vt(e,n,!0)?n:null},_t=function(e,t){var n,r,o=e.endContainer;if(i(o))n=l(o,t);else if(a(o))n=o;else{if(n=ft(o,e.endOffset),!n||!p(t,n))for(n=t;r=n.lastChild;)n=r;n=l(n,t)}return n&&vt(e,n,!0)?n:null},yt=new n(null,H|M,function(e){return e.nodeType===I?at.test(e.data):"IMG"===e.nodeName}),Tt=function(e,t){var n,r=e.startContainer,o=e.startOffset;if(yt.root=null,r.nodeType===I){if(o)return!1;n=r}else if(n=ft(r,o),n&&!p(t,n)&&(n=null),!n&&(n=ht(r,o),n.nodeType===I&&n.length))return!1;return yt.currentNode=n,yt.root=St(e,t),!yt.previousNode()},bt=function(e,t){var n,r=e.endContainer,o=e.endOffset;if(yt.root=null,r.nodeType===I){if(n=r.data.length,n&&n>o)return!1;yt.currentNode=r}else yt.currentNode=ht(r,o);return yt.root=_t(e,t),!yt.nextNode()},Et=function(e,t){var n,r=St(e,t),o=_t(e,t);r&&o&&(n=r.parentNode,e.setStart(n,st.call(n.childNodes,r)),n=o.parentNode,e.setEnd(n,st.call(n.childNodes,o)+1))},xt={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},kt=function(e){var t=e.keyCode,n=xt[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),X&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-")),e.shiftKey&&(r+="shift-"),n=r+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,o):1!==n.length||o.collapsed||(this.saveUndoState(o),gt(o,this._root),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},Ot=function(e){return function(t,n){n.preventDefault(),t[e]()}},Lt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Bt=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===I&&(r=r.parentNode),n=r;i(n)&&(!n.textContent||n.textContent===Z);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,st.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),a(n)||(n=l(n,e._root)),_(n,e._root),Ct(t)),r===e._root&&(r=r.firstChild)&&"BR"===r.nodeName&&v(r),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(o){e.didError(o)}},At={enter:function(e,t,n){var r,o,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),pn(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||gt(n,a),r=St(n,a),!r||/^T[HD]$/.test(r.nodeName))return ut(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((o=u(r,a,"LI"))&&(r=o),!r.textContent){if(u(r,a,"UL")||u(r,a,"OL"))return e.modifyBlocks(fn,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(an,n)}for(i=nn(e,r,n.startContainer,n.startOffset),Xt(r),Ht(r),_(r,a);i.nodeType===P;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===Z)){d=e._doc.createTextNode(""),C(i,d),i=d;break}for(;d&&d.nodeType===I&&!d.data&&(s=d.nextSibling,s&&"BR"!==s.nodeName);)v(d),d=s;if(!d||"BR"===d.nodeName||d.nodeType===I&&!X)break;i=d}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){var r=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Tt(n,r)){t.preventDefault();var o,i=St(n,r);if(!i)return;if(y(i.parentNode,r),o=l(i,r)){if(!o.isContentEditable)return void v(o);for(E(o,i,n),i=o.parentNode;i!==r&&!i.nextSibling;)i=i.parentNode;i!==r&&(i=i.nextSibling)&&x(i,r),e.setSelection(n)}else if(i){if(u(i,r,"UL")||u(i,r,"OL"))return e.modifyBlocks(fn,n);if(u(i,r,"BLOCKQUOTE"))return e.modifyBlocks(on,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Bt(e)},0);else t.preventDefault(),gt(n,r),Bt(e,n)},"delete":function(e,t,n){var r,o,i,a,s,d,l=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(bt(n,l)){if(t.preventDefault(),r=St(n,l),!r)return;if(y(r.parentNode,l),o=c(r,l)){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o!==l&&!o.nextSibling;)o=o.parentNode;o!==l&&(o=o.nextSibling)&&x(o,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(i=n.cloneRange(),Nt(n,e._root),a=n.endContainer,s=n.endOffset,a.nodeType===P&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),v(d),Ct(n),void Bt(e,n);e.setSelection(i),setTimeout(function(){Bt(e)},0)}else t.preventDefault(),gt(n,l),Bt(e,n)},tab:function(e,t,n){var r,o,i=e._root;if(e._removeZWS(),n.collapsed&&Tt(n,i))for(r=St(n,i);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(hn,n));break}r=o}},"shift-tab":function(e,t,n){var r,o=e._root;e._removeZWS(),n.collapsed&&Tt(n,o)&&(r=n.startContainer,(u(r,o,"UL")||u(r,o,"OL"))&&(t.preventDefault(),e.modifyBlocks(fn,n)))},space:function(e,t,n){var r,o;e._recordUndoState(n),pn(n.startContainer,e._root,e),e._getRangeAndRemoveBookmark(n),r=n.endContainer,o=r.parentNode,n.collapsed&&"A"===o.nodeName&&!r.nextSibling&&n.endOffset===m(r)&&n.setStartAfter(o),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&$&&(At["meta-left"]=function(e,t){t.preventDefault();var n=Yt(e);n&&n.modify&&n.modify("move","backward","lineboundary")},At["meta-right"]=function(e,t){t.preventDefault();var n=Yt(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),V||(At.pageup=function(e){e.moveCursorToStart()},At.pagedown=function(e){e.moveCursorToEnd()}),At[tt+"b"]=Lt("B"),At[tt+"i"]=Lt("I"),At[tt+"u"]=Lt("U"),At[tt+"shift-7"]=Lt("S"),At[tt+"shift-5"]=Lt("SUB",{tag:"SUP"}),At[tt+"shift-6"]=Lt("SUP",{tag:"SUB"}),At[tt+"shift-8"]=Ot("makeUnorderedList"),At[tt+"shift-9"]=Ot("makeOrderedList"),At[tt+"["]=Ot("decreaseQuoteLevel"),At[tt+"]"]=Ot("increaseQuoteLevel"),At[tt+"y"]=Ot("redo"),At[tt+"z"]=Ot("undo"),At[tt+"shift-z"]=Ot("redo");var Dt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Rt={backgroundColor:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color:"+t})}},color:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ut=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Pt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Rt)r=Rt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ut("B"),EM:Ut("I"),STRIKE:Ut("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+Dt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},It=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/,wt=/^(?:HEAD|META|STYLE)/,Ft=new n(null,H|M,function(){return!0}),Mt=function vn(e,t){var n,r,o,a,s,d,l,c,h,f,u,p,g=e.childNodes;for(n=e;i(n);)n=n.parentNode;for(Ft.root=n,r=0,o=g.length;o>r;r+=1)if(a=g[r],s=a.nodeName,d=a.nodeType,l=Pt[s],d===P){if(c=a.childNodes.length,l)a=l(a,e);else{if(wt.test(s)){e.removeChild(a),r-=1,o-=1;continue}if(!It.test(s)&&!i(a)){r-=1,o+=c-1,e.replaceChild(N(a),a);continue}}c&&vn(a,t||"PRE"===s)}else{if(d===I){if(u=a.data,h=!at.test(u.charAt(0)),f=!at.test(u.charAt(u.length-1)),t||!h&&!f)continue;if(h){for(Ft.currentNode=a;(p=Ft.previousPONode())&&(s=p.nodeName,!("IMG"===s||"#text"===s&&/\S/.test(p.data)));)if(!i(p)){p=null;break}u=u.replace(/^\s+/g,p?" ":"")}if(f){for(Ft.currentNode=a;(p=Ft.nextNode())&&!("IMG"===s||"#text"===s&&/\S/.test(p.data));)if(!i(p)){p=null;break}u=u.replace(/\s+$/g,p?" ":"")}if(u){a.data=u;continue}}e.removeChild(a),r-=1,o-=1}return e},Ht=function Cn(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==P||o(t)?t.nodeType!==I||t.data||e.removeChild(t):(Cn(t),i(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e){return e.nodeType===P?"BR"===e.nodeName:at.test(e.data)},zt=function(e){for(var t,r=e.parentNode;i(r);)r=r.parentNode;return t=new n(r,M|H,Wt),t.currentNode=e,!!t.nextNode()},qt=function(e,t){var n,r,o,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=zt(a[n]);for(;d--;)r=a[d],o=r.parentNode,o&&(s[d]?i(o)||y(o,t):v(r))},Kt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._root,i=this;this.saveUndoState(n),J||Q||!t?setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0):(Nt(n,o),r.appendChild(gt(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},Zt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");J||Q||!t||(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},Gt=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,h=this;if(!J&&s){for(e.preventDefault(),t=s.length;t--;){if(n=s[t],r=n.type,"text/html"===r)return void n.getAsString(function(e){h.insertHTML(e,!0)});"text/plain"===r&&(c=n),/^image\/.*/.test(r)&&(l=!0)}return void(l?(this.fireEvent("dragover",{dataTransfer:a,preventDefault:function(){d=!0}}),d&&this.fireEvent("drop",{dataTransfer:a})):c&&n.getAsString(function(e){h.insertPlainText(e,!0)}))}if(o=a&&a.types,!J&&o&&(st.call(o,"text/html")>-1||!$&&st.call(o,"text/plain")>-1&&st.call(o,"text/rtf")<0))return e.preventDefault(),void((i=a.getData("text/html"))?this.insertHTML(i,!0):((i=a.getData("text/plain"))||(i=a.getData("text/uri-list")))&&this.insertPlainText(i,!0));this._awaitingPaste=!0;var f=this._doc.body,u=this.getSelection(),p=u.startContainer,g=u.startOffset,m=u.endContainer,C=u.endOffset,N=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(N),u.selectNodeContents(N),this.setSelection(u),setTimeout(function(){try{h._awaitingPaste=!1;for(var e,t,n="",r=N;N=r;)r=N.nextSibling,v(N),e=N.firstChild,e&&e===N.lastChild&&"DIV"===e.nodeName&&(N=e),n+=N.innerHTML;t=h._createRange(p,g,m,C),h.setSelection(t),n&&h.insertHTML(n,!0)}catch(o){h.didError(o)}},0)},jt=function(e){for(var t=e.dataTransfer.types,n=t.length,r=!1,o=!1;n--;)switch(t[n]){case"text/plain":r=!0;break;case"text/html":o=!0;break;default:return}(o||r)&&this.saveUndoState()},Qt=[],Vt=L.prototype;Vt.setConfig=function(e){return e=O({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},Vt.createElement=function(e,t,n){return S(this._doc,e,t,n)},Vt.createDefaultBlock=function(e){var t=this._config;return _(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},Vt.didError=function(e){console.log(e)},Vt.getDocument=function(){return this._doc},Vt.getRoot=function(){return this._root},Vt.modifyDocument=function(e){this._ignoreAllChanges=!0,this._mutation&&this._mutation.disconnect(),e(),this._ignoreAllChanges=!1,this._mutation&&this._mutation.observe(this._root,{childList:!0,attributes:!0,characterData:!0,subtree:!0})};var $t={pathChange:1,select:1,input:1,undoStateChange:1};Vt.fireEvent=function(e,t){var n,r,o=this._events[e];if(o)for(t||(t={}),t.type!==e&&(t.type=e),o=o.slice(),n=o.length;n--;){r=o[n];try{r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(i){i.details="Squire: fireEvent error. Event type: "+e,this.didError(i)}}return this},Vt.destroy=function(){var e,t=Qt.length,n=this._events;for(e in n)this.removeEventListener(e);for(this._mutation&&this._mutation.disconnect();t--;)Qt[t]===this&&Qt.splice(t,1)},Vt.handleEvent=function(e){this.fireEvent(e.type,e)},Vt.addEventListener=function(e,t){var n=this._events[e],r=this._root;return t?(n||(n=this._events[e]=[],$t[e]||("selectionchange"===e&&(r=this._doc),r.addEventListener(e,this,!0))),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Vt.removeEventListener=function(e,t){var n,r=this._events[e],o=this._root;if(r){if(t)for(n=r.length;n--;)r[n]===t&&r.splice(n,1);else r.length=0;r.length||(delete this._events[e],$t[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},Vt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Vt.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,r=e.getBoundingClientRect();return r&&!r.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=Z,ut(e,t),r=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),b(n,{startContainer:e.startContainer,endContainer:e.endContainer,startOffset:e.startOffset,endOffset:e.endOffset})),r},Vt._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return Ct(n),this.setSelection(n),this},Vt.moveCursorToStart=function(){return this._moveCursorTo(!0)},Vt.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var Yt=function(e){return e._win.getSelection()||null};Vt.setSelection=function(e){if(e){this._restoreSelection=!1,this._lastSelection=e,Q&&this._win.focus();var t=Yt(this);t&&(t.removeAllRanges(),t.addRange(e))}return this},Vt.getSelection=function(){var e,t,n,r=Yt(this),i=this._root;return r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&o(t)&&e.setStartBefore(t),n&&o(n)&&e.setEndBefore(n)),e&&p(i,e.commonAncestorContainer)?this._lastSelection=e:e=this._lastSelection,e||(e=this._createRange(i.firstChild,0)),e},Vt.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,H|M,function(e){return vt(t,e,!0)}),o=t.startContainer,a=t.endContainer,s=r.currentNode=o,d="",l=!1;for(r.filter(s)||(s=r.nextNode());s;)s.nodeType===I?(e=s.data,e&&/\S/.test(e)&&(s===a&&(e=e.slice(0,t.endOffset)),s===o&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===s.nodeName||l&&!i(s))&&(d+="\n",l=!1),s=r.nextNode();return d},Vt.getPath=function(){return this._path};var Xt=function(e){for(var t,r,o,a=new n(e,H,function(){return!0},!1);r=a.nextNode();)for(;(o=r.data.indexOf(Z))>-1;){if(1===r.length){do t=r.parentNode,t.removeChild(r),r=t,a.currentNode=t;while(i(r)&&!m(r));break}r.deleteData(o,1)}};Vt._didAddZWS=function(){this._hasZWS=!0},Vt._removeZWS=function(){this._hasZWS&&(Xt(this._root),this._hasZWS=!1)},Vt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?g(o,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},Vt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Vt.focus=function(){return this._root.focus(),this},Vt.blur=function(){return this._root.blur(),this};var Jt="squire-selection-start",en="squire-selection-end";Vt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Jt,type:"hidden"}),r=this.createElement("INPUT",{id:en,type:"hidden"});ut(e,n),e.collapse(!1),ut(e,r),n.compareDocumentPosition(r)&U&&(n.id=en,r.id=Jt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Vt._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+Jt),r=t.querySelector("#"+en);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:st.call(i.childNodes,n),endOffset:st.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),b(i,s),i!==a&&b(a,s),e||(e=this._doc.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,o&&(i=e.startContainer,i.nodeType===I&&(a=i.childNodes[e.startOffset],a&&a.nodeType===I||(a=i.childNodes[e.startOffset-1]),a&&a.nodeType===I&&(e.setStart(a,0),e.collapse(!0))))}return e||null},Vt._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},Vt._docWasChanged=function(){if(!this._ignoreAllChanges){if(it&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},Vt._recordUndoState=function(e){if(!this._isInUndoState){var t=this._undoIndex+=1,n=this._undoStack;te+1&&this._isInUndoState){this._undoIndex+=1,this._setHTML(this._undoStack[this._undoIndex]);var n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:t>e+2}),this.fireEvent("input")}return this},Vt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;!r.collapsed&&r.startContainer.nodeType===I&&r.startOffset===r.startContainer.length&&r.startContainer.nextSibling&&r.setStartBefore(r.startContainer.nextSibling),!r.collapsed&&r.endContainer.nodeType===I&&0===r.endOffset&&r.endContainer.previousSibling&&r.setEndAfter(r.endContainer.previousSibling);var o,i,a=this._root,s=r.commonAncestorContainer;if(u(s,a,e,t))return!0;if(s.nodeType===I)return!1;o=new n(s,H,function(e){return vt(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},Vt.getFontInfo=function(e){var n,r,o,i={color:t,backgroundColor:t,family:t,size:t},a=0;if(!e&&!(e=this.getSelection()))return i;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===I)for(n.nodeType===I&&(n=n.parentNode);4>a&&n;)(r=n.style)&&(!i.color&&(o=r.color)&&(i.color=o,a+=1),!i.backgroundColor&&(o=r.backgroundColor)&&(i.backgroundColor=o,a+=1),!i.family&&(o=r.fontFamily)&&(i.family=o,a+=1),!i.size&&(o=r.fontSize)&&(i.size=o,a+=1)),n=n.parentNode;return i},Vt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,h,f=this._root;if(r.collapsed)o=_(this.createElement(e,t),f),ut(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{if(i=new n(r.commonAncestorContainer,H|M,function(e){return(e.nodeType===I||"BR"===e.nodeName||"IMG"===e.nodeName)&&vt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,i.filter(a)||(a=i.nextNode(),d=0),!a)return r;
-do c=i.currentNode,h=!u(c,f,e,t),h&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),s===a&&(s=c,l-=d),a=c,d=0),o=this.createElement(e,t),C(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==I&&(c.nodeType===I?(s=c,l=c.length):(s=c.parentNode,l=1)),r=this._createRange(a,d,s,l)}return r},Vt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var o,a=this._doc;n.collapsed&&(rt?(o=a.createTextNode(Z),this._didAddZWS()):o=a.createTextNode(""),ut(n,o));for(var s=n.commonAncestorContainer;i(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!vt(n,e,!1)){var r,o,i=e.nodeType===I;if(!vt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===c&&h!==e.length&&u.push([t,e.splitText(h)]),e===d&&l&&(e.splitText(l),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(r){return vt(n,r,!0)&&f(r,e,t)});r||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,N(e))}),this._getRangeAndRemoveBookmark(n),o&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return b(s,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},Vt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),it||this._docWasChanged(),this):void 0};var tn={DT:"DD",DD:"DT",LI:"LI"},nn=function(e,t,n,r){var o=tn[t.nodeName],i=null,a=T(n,r,t.parentNode,e._root),s=e._config;return o||(o=s.blockTag,i=s.blockAttributes),f(a,o,i)||(t=S(a.ownerDocument,o,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(N(a)),a=t),a};Vt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,o=St(n,r),i=_t(n,r);if(o&&i)do if(e(o)||o===i)break;while(o=c(o,r));return t&&(this.setSelection(n),this._updatePath(n,!0),it||this._docWasChanged()),this},Vt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t);var n,r=this._root;return Et(t,r),Nt(t,r),n=pt(t,r,r),ut(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],C(s,N(s));y(i,this._root),C(o,i)}return e},hn=function(e){var t,n,r,o,i,a,d=e.querySelectorAll("LI"),l=this._config.tagAttributes,c=l.li;for(t=0,n=d.length;n>t;t+=1)r=d[t],s(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||(a=l[o.toLowerCase()],C(r,this.createElement("LI",c,[i=this.createElement(o,a)]))),i.appendChild(r));return e},fn=function(e){var t=this._root,n=e.querySelectorAll("LI");return Array.prototype.filter.call(n,function(e){return!s(e.firstChild)}).forEach(function(n){var r,o=n.parentNode,i=o.parentNode,a=n.firstChild,d=a;for(n.previousSibling&&(o=T(o,n,i,t));d&&(r=d.nextSibling,!s(d));)i.insertBefore(d,o),d=r;for("LI"===i.nodeName&&a.previousSibling&&T(i,a,i.parentNode,t);n!==e&&!n.childNodes.length;)o=n.parentNode,o.removeChild(n),n=o},this),y(e,t),e};Vt._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},Vt.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},Vt._getHTML=function(){return this._root.innerHTML},Vt._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do _(n,t);while(n=c(n,t));this._ignoreChange=!0},Vt.getHTML=function(e){var t,n,r,o,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),nt)for(t=this._root,n=t;n=c(n,t);)n.textContent||n.querySelector("BR")||(r=this.createElement("BR"),n.appendChild(r),s.push(r));if(o=this._getHTML().replace(/\u200B/g,""),nt)for(i=s.length;i--;)v(s[i]);return a&&this._getRangeAndRemoveBookmark(a),o},Vt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),o=this._root;r.innerHTML=e,n.appendChild(N(r)),Mt(n),qt(n,o),y(n,o);for(var i=n;i=c(i,o);)_(i,o);for(this._ignoreChange=!0;t=o.lastChild;)o.removeChild(t);o.appendChild(n),_(o,o),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var a=this._getRangeAndRemoveBookmark()||this._createRange(o.firstChild,0);return this.saveUndoState(a),this._lastSelection=a,this._updatePath(a,!0),this},Vt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),i(e))ut(t,e),t.setStartAfter(e);else{for(var n,r,o=this._root,a=St(t,o)||o;a!==o&&!a.nextSibling;)a=a.parentNode;a!==o&&(n=a.parentNode,r=T(n,a.nextSibling,o,o)),r?o.insertBefore(e,r):(o.appendChild(e),r=this.createDefaultBlock(),o.appendChild(r)),t.setStart(r,0),t.setEnd(r,0),Ct(t)}return this.focus(),this.setSelection(t),this._updatePath(t),it||this._docWasChanged(),this},Vt.insertImage=function(e,t){var n=this.createElement("IMG",O({src:e},t));return this.insertElement(n),n};var un=/\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,pn=function(e,t,r){for(var o,i,a,s,d,l,c,h=e.ownerDocument,f=new n(e,H,function(e){return!u(e,t,"A")},!1),p=r._config.tagAttributes.a;o=f.nextNode();)for(i=o.data,a=o.parentNode;s=un.exec(i);)d=s.index,l=d+s[0].length,d&&(c=h.createTextNode(i.slice(0,d)),a.insertBefore(c,o)),c=r.createElement("A",O({href:s[1]?/^(?:ht|f)tps?:/.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[2]},p)),c.textContent=i.slice(d,l),a.insertBefore(c,o),o.data=i=i.slice(l)};Vt.insertHTML=function(e,t){var n,r,o,i,a,s=this.getSelection(),d=this._doc.createDocumentFragment(),l=this.createElement("DIV");t&&(n=e.indexOf(""),r=e.lastIndexOf(""),n>-1&&r>-1&&(e=e.slice(n+20,r))),l.innerHTML=e,d.appendChild(N(l)),this.saveUndoState(s);try{for(o=this._root,i=d,a={fragment:d,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},pn(d,d,this),Mt(d),qt(d,null),Ht(d),d.normalize();i=c(i,d);)_(i,null);t&&this.fireEvent("willPaste",a),a.defaultPrevented||(mt(s,a.fragment,o),it||this._docWasChanged(),s.collapse(!1),this._ensureBottomLine()),this.setSelection(s),this._updatePath(s,!0)}catch(h){this.didError(h)}return this};var gn=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};Vt.insertPlainText=function(e,t){var n,r,o,i,a=e.split("\n"),s=this._config,d=s.blockTag,l=s.blockAttributes,c=""+d+">",h="<"+d;for(n in l)h+=" "+n+'="'+gn(l[n])+'"';for(h+=">",r=0,o=a.length;o>r;r+=1)i=a[r],i=gn(i).replace(/ (?= )/g," "),r&&o>r+1&&(i=h+(i||"
")+c),a[r]=i;return this.insertHTML(a.join(""),t)};var mn=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Vt.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},Vt.bold=mn("changeFormat",{tag:"B"}),Vt.italic=mn("changeFormat",{tag:"I"}),Vt.underline=mn("changeFormat",{tag:"U"}),Vt.strikethrough=mn("changeFormat",{tag:"S"}),Vt.subscript=mn("changeFormat",{tag:"SUB"},{tag:"SUP"}),Vt.superscript=mn("changeFormat",{tag:"SUP"},{tag:"SUB"}),Vt.removeBold=mn("changeFormat",null,{tag:"B"}),Vt.removeItalic=mn("changeFormat",null,{tag:"I"}),Vt.removeUnderline=mn("changeFormat",null,{tag:"U"}),Vt.removeStrikethrough=mn("changeFormat",null,{tag:"S"}),Vt.removeSubscript=mn("changeFormat",null,{tag:"SUB"}),Vt.removeSuperscript=mn("changeFormat",null,{tag:"SUP"}),Vt.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;ut(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),O(t,this._config.tagAttributes.a),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},Vt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Vt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Vt.setFontSize=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}},{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},Vt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Vt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Vt.setTextAlignment=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/align/.test(e)}).join(" ")+" align-"+e).trim(),t.style.textAlign=e},!0),this.focus()},Vt.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},Vt.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=this._root,n=e.commonAncestorContainer;n&&!a(n);)n=n.parentNode;if(n||(Et(e,t),n=t),n.nodeType===I)return this;this.saveUndoState(e),Nt(e,n);for(var r,o,i,s=n.ownerDocument,d=e.startContainer,l=e.startOffset,c=e.endContainer,h=e.endOffset,f=s.createDocumentFragment(),u=s.createDocumentFragment(),p=T(c,h,n,t),g=T(d,l,n,t);g!==p;)r=g.nextSibling,f.appendChild(g),g=r;return R(this,f,u),u.normalize(),g=u.firstChild,r=u.lastChild,i=n.childNodes,g?(n.insertBefore(u,p),l=st.call(i,g),h=st.call(i,r)+1):(l=st.call(i,p),h=l),o={startContainer:n,startOffset:l,endContainer:n,endOffset:h},b(n,o),e.setStart(o.startContainer,o.startOffset),e.setEnd(o.endContainer,o.endOffset),Ct(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},Vt.increaseQuoteLevel=mn("modifyBlocks",rn),Vt.decreaseQuoteLevel=mn("modifyBlocks",on),Vt.makeUnorderedList=mn("modifyBlocks",dn),Vt.makeOrderedList=mn("modifyBlocks",ln),Vt.removeList=mn("modifyBlocks",cn),Vt.increaseListLevel=mn("modifyBlocks",hn),Vt.decreaseListLevel=mn("modifyBlocks",fn),"object"==typeof exports?module.exports=L:"function"==typeof define&&define.amd?define(function(){return L}):(G.Squire=L,top!==G&&"true"===e.documentElement.getAttribute("data-squireinit")&&(G.editor=new L(e),G.onEditorLoad&&(G.onEditorLoad(G.editor),G.onEditorLoad=null)))}(document);
\ No newline at end of file
+!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function o(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function i(e){return e.nodeType===w&&!!Ct[e.nodeName]}function r(e){return vt.test(e.nodeName)}function a(e){var t=e.nodeType;return(t===w||t===H)&&!r(e)&&o(e.childNodes,r)}function s(e){var t=e.nodeType;return!(t!==w&&t!==H||r(e)||a(e))}function d(e,t){var o=new n(t,W,a);return o.currentNode=e,o}function l(e,t){return e=d(e,t).previousNode(),e!==t?e:null}function c(e,t){return e=d(e,t).nextNode(),e!==t?e:null}function h(e,t){return!i(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&"A"!==e.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function u(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 f(e,t,n,o){for(;e&&e!==t;){if(u(e,n,o))return e;e=e.parentNode}return null}function p(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function g(e,t){var n,o,i,r,a="";return e&&e!==t&&(a=g(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&&(gt.call(i,j)>-1&&(a+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),gt.call(i,Q)>-1&&(a+="[color="+e.style.color.replace(/ /g,"")+"]"),gt.call(i,V)>-1&&(a+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),gt.call(i,$)>-1&&(a+="[fontSize="+e.style.fontSize+"]")))),a}function m(e){var t=e.nodeType;return t===w?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,o=n?n.length:0;o--;)t.appendChild(e.firstChild);return t}function _(e,n,o,i){var r,a,s,d,l=e.createElement(n);if(o instanceof Array&&(i=o,o=null),o)for(r in o)a=o[r],a!==t&&l.setAttribute(r,o[r]);if(i)for(s=0,d=i.length;d>s;s+=1)l.appendChild(i[s]);return l}function S(e,t){var n,o,a=e.ownerDocument,s=e;if(e===t&&((o=e.firstChild)&&"BR"!==o.nodeName||(n=L(a).createDefaultBlock(),o?e.replaceChild(n,o):e.appendChild(n),e=n,n=null)),e.nodeType===F)return s;if(r(e)){for(o=e.firstChild;ht&&o&&o.nodeType===F&&!o.data;)e.removeChild(o),o=e.firstChild;o||(ht?(n=a.createTextNode(Y),L(a)._didAddZWS()):n=a.createTextNode(""))}else if(ct){for(;e.nodeType!==F&&!i(e);){if(o=e.firstChild,!o){n=a.createTextNode("");break}e=o}e.nodeType===F?/^ +$/.test(e.data)&&(e.data=""):i(e)&&e.parentNode.insertBefore(a.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=_(a,"BR");(o=e.lastElementChild)&&!r(o);)e=o;if(n)try{e.appendChild(n)}catch(d){L(a).didError({name:"Squire: fixCursor – "+d,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return s}function y(e,t){var n,o,i,a,d=e.childNodes,l=e.ownerDocument,c=null,h=L(l)._config;for(n=0,o=d.length;o>n;n+=1)i=d[n],a="BR"===i.nodeName,!a&&r(i)?(c||(c=_(l,h.blockTag,h.blockAttributes)),c.appendChild(i),n-=1,o-=1):(a||c)&&(c||(c=_(l,h.blockTag,h.blockAttributes)),S(c,t),a?e.replaceChild(c,i):(e.insertBefore(c,i),n+=1,o+=1),c=null),s(i)&&y(i,t);return c&&e.appendChild(S(c,t)),e}function T(e,t,n,o){var i,r,a,s=e.nodeType;if(s===F&&e!==n)return T(e.parentNode,e.splitText(t),n,o);if(s===w){if("number"==typeof t&&(t=ts?t.startOffset-=1:t.startOffset===s&&(t.startContainer=o,t.startOffset=m(o))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=o,t.endOffset=m(o))),v(n),n.nodeType===F?o.appendData(n.data):d.push(N(n));else if(n.nodeType===w){for(i=d.length;i--;)n.appendChild(d.pop());E(n,t)}}function b(e,t){if(e.nodeType===F&&(e=e.parentNode),e.nodeType===w){var n={startContainer:t.startContainer,startOffset:t.startOffset,endContainer:t.endContainer,endOffset:t.endOffset};E(e,n),t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset)}}function k(e,t,n){for(var o,i,r=t;1===r.parentNode.childNodes.length;)r=r.parentNode;v(r),i=e.childNodes.length,o=e.lastChild,o&&"BR"===o.nodeName&&(e.removeChild(o),i-=1),e.appendChild(N(t)),n.setStart(e,i),n.collapse(!0),b(e,n),rt&&(o=e.lastChild)&&"BR"===o.nodeName&&e.removeChild(o)}function x(e,t){var n,o,i=e.previousSibling,r=e.firstChild,a=e.ownerDocument,d="LI"===e.nodeName;if(!d||r&&/^[OU]L$/.test(r.nodeName))if(i&&h(i,e)){if(!s(i)){if(!d)return;o=_(a,"DIV"),o.appendChild(N(i)),i.appendChild(o)}v(e),n=!s(e),i.appendChild(N(e)),n&&y(i,t),r&&x(r,t)}else d&&(i=_(a,"DIV"),e.insertBefore(i,r),S(i,t))}function B(e){this.isShiftDown=e.shiftKey}function L(e){for(var t,n=on.length;n--;)if(t=on[n],t._doc===e)return t;return null}function A(e,t,n){var o,i;if(e||(e={}),t)for(o in t)!n&&o in e||(i=t[o],e[o]=i&&i.constructor===Object?A(e[o],i,n):i);return e}function O(e,t){e.nodeType===M&&(e=e.body);var n,o=e.ownerDocument,i=o.defaultView;this._win=i,this._doc=o,this._root=e,this._events={},this._isFocused=!1,this._lastSelection=null,ut&&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,ft?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._restoreSelection=!1,this.addEventListener("blur",D),this.addEventListener("mousedown",R),this.addEventListener("touchstart",R),this.addEventListener("focus",U),this._awaitingPaste=!1,this.addEventListener(it?"beforecut":"cut",Jt),this.addEventListener("copy",en),this.addEventListener("keydown",B),this.addEventListener("keyup",B),this.addEventListener(it?"beforepaste":"paste",tn),this.addEventListener("drop",nn),this.addEventListener(rt?"keypress":"keydown",Pt),this._keyHandlers=Object.create(Mt),this.setConfig(t),it&&(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(r){}on.push(this),this.setHTML("")}function D(){this._restoreSelection=!0}function R(){this._restoreSelection=!1}function U(){this._restoreSelection&&this.setSelection(this._lastSelection)}function P(e,t,n){var o,i;for(o=t.firstChild;o;o=i){if(i=o.nextSibling,r(o)){if(o.nodeType===F||"BR"===o.nodeName||"IMG"===o.nodeName){n.appendChild(o);continue}}else if(a(o)){n.appendChild(e.createDefaultBlock([P(e,o,e._doc.createDocumentFragment())]));continue}P(e,o,n)}return n}var I=2,w=1,F=3,M=9,H=11,W=1,z=4,q=0,K=1,Z=2,G=3,j="highlight",Q="colour",V="font",$="size",Y="",X=e.defaultView,J=navigator.userAgent,et=/iP(?:ad|hone|od)/.test(J),tt=/Mac OS X/.test(J),nt=/Android/.test(J),ot=/Gecko\//.test(J),it=/Trident\/[456]\./.test(J),rt=!!X.opera,at=/Edge\//.test(J),st=!at&&/WebKit\//.test(J),dt=/Trident\/[4567]\./.test(J),lt=tt?"meta-":"ctrl-",ct=it||rt,ht=it||st,ut=it,ft="undefined"!=typeof MutationObserver,pt=/[^ \t\r\n]/,gt=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var mt={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,i=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(mt[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(mt[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,i=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)e=t.previousSibling,e||(t=t.parentNode);if(!e)return null;if(mt[e.nodeType]&o&&i(e))return this.currentNode=e,e;t=e}};var vt=/^(?:#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)$/,Ct={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},Nt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===w;)e=n[t-1],n=e.childNodes,t=n.length;return e},_t=function(e,t){if(e.nodeType===w){var n=e.childNodes;if(t-1,r=e.compareBoundaryPoints(K,o)<1;return!i&&!r}var a=e.compareBoundaryPoints(q,o)<1,s=e.compareBoundaryPoints(Z,o)>-1;return a&&s},kt=function(e){for(var t,n=e.startContainer,o=e.startOffset,r=e.endContainer,a=e.endOffset;n.nodeType!==F&&(t=n.childNodes[o],t&&!i(t));)n=t,o=0;if(a)for(;r.nodeType!==F&&(t=r.childNodes[a-1],t&&!i(t));)r=t,a=m(r);else for(;r.nodeType!==F&&(t=r.firstChild,t&&!i(t));)r=t;e.collapsed?(e.setStart(r,a),e.setEnd(n,o)):(e.setStart(n,o),e.setEnd(r,a))},xt=function(e,t){var n,o=e.startContainer,i=e.startOffset,r=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);o!==t&&!i;)n=o.parentNode,i=gt.call(n.childNodes,o),o=n;for(;r!==t&&a===m(r);)n=r.parentNode,a=gt.call(n.childNodes,r)+1,r=n;e.setStart(o,i),e.setEnd(r,a)},Bt=function(e,t){var n,o=e.startContainer;return r(o)?n=l(o,t):a(o)?n=o:(n=Nt(o,e.startOffset),n=c(n,t)),n&&bt(e,n,!0)?n:null},Lt=function(e,t){var n,o,i=e.endContainer;if(r(i))n=l(i,t);else if(a(i))n=i;else{if(n=_t(i,e.endOffset),!n||!p(t,n))for(n=t;o=n.lastChild;)n=o;n=l(n,t)}return n&&bt(e,n,!0)?n:null},At=new n(null,z|W,function(e){return e.nodeType===F?pt.test(e.data):"IMG"===e.nodeName}),Ot=function(e,t){var n,o=e.startContainer,i=e.startOffset;if(At.root=null,o.nodeType===F){if(i)return!1;n=o}else if(n=_t(o,i),n&&!p(t,n)&&(n=null),!n&&(n=Nt(o,i),n.nodeType===F&&n.length))return!1;return At.currentNode=n,At.root=Bt(e,t),!At.previousNode()},Dt=function(e,t){var n,o=e.endContainer,i=e.endOffset;if(At.root=null,o.nodeType===F){if(n=o.data.length,n&&n>i)return!1;At.currentNode=o}else At.currentNode=Nt(o,i);return At.root=Lt(e,t),!At.nextNode()},Rt=function(e,t){var n,o=Bt(e,t),i=Lt(e,t);o&&i&&(n=o.parentNode,e.setStart(n,gt.call(n.childNodes,o)),n=i.parentNode,e.setEnd(n,gt.call(n.childNodes,i)+1))},Ut={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},Pt=function(e){var t=e.keyCode,n=Ut[t],o="",i=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),rt&&46===e.which&&(n="."),t>111&&124>t&&(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):1!==n.length||i.collapsed||(this.saveUndoState(i),Tt(i,this._root),this._ensureBottomLine(),this.setSelection(i),this._updatePath(i,!0)))},It=function(e){return function(t,n){n.preventDefault(),t[e]()}},wt=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)}},Ft=function(e,t){try{t||(t=e.getSelection());var n,o=t.startContainer;for(o.nodeType===F&&(o=o.parentNode),n=o;r(n)&&(!n.textContent||n.textContent===Y);)o=n,n=o.parentNode;o!==n&&(t.setStart(n,gt.call(n.childNodes,o)),t.collapse(!0),n.removeChild(o),a(n)||(n=l(n,e._root)),S(n,e._root),kt(t)),o===e._root&&(o=o.firstChild)&&"BR"===o.nodeName&&v(o),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(i){e.didError(i)}},Mt={enter:function(e,t,n){var o,i,r,a=e._root;if(t.preventDefault(),e._recordUndoState(n),Tn(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||Tt(n,a),o=Bt(n,a),!o||/^T[HD]$/.test(o.nodeName))return St(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((i=f(o,a,"LI"))&&(o=i),!o.textContent){if(f(o,a,"UL")||f(o,a,"OL"))return e.modifyBlocks(Sn,n);if(f(o,a,"BLOCKQUOTE"))return e.modifyBlocks(gn,n)}for(r=un(e,o,n.startContainer,n.startOffset),dn(o),Vt(o),S(o,a);r.nodeType===w;){var s,d=r.firstChild;if("A"===r.nodeName&&(!r.textContent||r.textContent===Y)){d=e._doc.createTextNode(""),C(r,d),r=d;break}for(;d&&d.nodeType===F&&!d.data&&(s=d.nextSibling,s&&"BR"!==s.nodeName);)v(d),d=s;if(!d||"BR"===d.nodeName||d.nodeType===F&&!rt)break;r=d}n=e._createRange(r,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){var o=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Ot(n,o)){t.preventDefault();var i,r=Bt(n,o);if(!r)return;if(y(r.parentNode,o),i=l(r,o)){if(!i.isContentEditable)return void v(i);for(k(i,r,n),r=i.parentNode;r!==o&&!r.nextSibling;)r=r.parentNode;r!==o&&(r=r.nextSibling)&&x(r,o),e.setSelection(n)}else if(r){if(f(r,o,"UL")||f(r,o,"OL"))return e.modifyBlocks(Sn,n);if(f(r,o,"BLOCKQUOTE"))return e.modifyBlocks(pn,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Ft(e)},0);else t.preventDefault(),Tt(n,o),Ft(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(Dt(n,l)){if(t.preventDefault(),o=Bt(n,l),!o)return;if(y(o.parentNode,l),i=c(o,l)){if(!i.isContentEditable)return void v(i);for(k(o,i,n),i=o.parentNode;i!==l&&!i.nextSibling;)i=i.parentNode;i!==l&&(i=i.nextSibling)&&x(i,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(r=n.cloneRange(),xt(n,e._root),a=n.endContainer,s=n.endOffset,a.nodeType===w&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),v(d),kt(n),void Ft(e,n);e.setSelection(r),setTimeout(function(){Ft(e)},0)}else t.preventDefault(),Tt(n,l),Ft(e,n)},tab:function(e,t,n){var o,i,r=e._root;if(e._removeZWS(),n.collapsed&&Ot(n,r))for(o=Bt(n,r);i=o.parentNode;){if("UL"===i.nodeName||"OL"===i.nodeName){o.previousSibling&&(t.preventDefault(),e.modifyBlocks(_n,n));break}o=i}},"shift-tab":function(e,t,n){var o,i=e._root;e._removeZWS(),n.collapsed&&Ot(n,i)&&(o=n.startContainer,(f(o,i,"UL")||f(o,i,"OL"))&&(t.preventDefault(),e.modifyBlocks(Sn,n)))},space:function(e,t,n){var o,i;e._recordUndoState(n),Tn(n.startContainer,e._root,e),e._getRangeAndRemoveBookmark(n),o=n.endContainer,i=o.parentNode,n.collapsed&&"A"===i.nodeName&&!o.nextSibling&&n.endOffset===m(o)?n.setStartAfter(i):n.collapsed||(Tt(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()}};tt&&ot&&(Mt["meta-left"]=function(e,t){t.preventDefault();var n=sn(e);n&&n.modify&&n.modify("move","backward","lineboundary")},Mt["meta-right"]=function(e,t){t.preventDefault();var n=sn(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),tt||(Mt.pageup=function(e){e.moveCursorToStart()},Mt.pagedown=function(e){e.moveCursorToEnd()}),Mt[lt+"b"]=wt("B"),Mt[lt+"i"]=wt("I"),Mt[lt+"u"]=wt("U"),Mt[lt+"shift-7"]=wt("S"),Mt[lt+"shift-5"]=wt("SUB",{tag:"SUP"}),Mt[lt+"shift-6"]=wt("SUP",{tag:"SUB"}),Mt[lt+"shift-8"]=It("makeUnorderedList"),Mt[lt+"shift-9"]=It("makeOrderedList"),Mt[lt+"["]=It("decreaseQuoteLevel"),Mt[lt+"]"]=It("increaseQuoteLevel"),Mt[lt+"y"]=It("redo"),Mt[lt+"z"]=It("undo"),Mt[lt+"shift-z"]=It("redo");var Ht={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Wt={backgroundColor:{regexp:pt,replace:function(e,t){return _(e,"SPAN",{"class":j,style:"background-color:"+t})}},color:{regexp:pt,replace:function(e,t){return _(e,"SPAN",{"class":Q,style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return _(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return _(e,"I")}},fontFamily:{regexp:pt,replace:function(e,t){return _(e,"SPAN",{"class":V,style:"font-family:"+t})}},fontSize:{regexp:pt,replace:function(e,t){return _(e,"SPAN",{"class":$,style:"font-size:"+t})}},textDecoration:{regexp:/^underline/i,replace:function(e){return _(e,"U")}}},zt=function(e){return function(t,n){var o=_(t.ownerDocument,e);return n.replaceChild(o,t),o.appendChild(N(t)),o}},qt=function(e,t){var n,o,i,r,a,s,d=e.style,l=e.ownerDocument;for(n in Wt)o=Wt[n],i=d[n],i&&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(N(e)),"SPAN"===e.nodeName?t.replaceChild(a,e):e.appendChild(a)),r||e},Kt={P:qt,SPAN:qt,STRONG:zt("B"),EM:zt("I"),INS:zt("U"),STRIKE:zt("S"),FONT:function(e,t){var n,o,i,r,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=_(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,r=n),d&&(o=_(c,"SPAN",{"class":"size",style:"font-size:"+Ht[d]+"px"}),a||(a=o),r&&r.appendChild(o),r=o),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),i=_(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=i),r&&r.appendChild(i),r=i),a||(a=r=_(c,"SPAN")),t.replaceChild(a,e),r.appendChild(N(e)),r},TT:function(e,t){var n=_(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Zt=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/,Gt=/^(?:HEAD|META|STYLE)/,jt=new n(null,z|W,function(){return!0}),Qt=function kn(e,t){var n,o,i,a,s,d,l,c,h,u,f,p,g=e.childNodes;for(n=e;r(n);)n=n.parentNode;for(jt.root=n,o=0,i=g.length;i>o;o+=1)if(a=g[o],s=a.nodeName,d=a.nodeType,l=Kt[s],d===w){if(c=a.childNodes.length,l)a=l(a,e);else{if(Gt.test(s)){e.removeChild(a),o-=1,i-=1;continue}if(!Zt.test(s)&&!r(a)){o-=1,i+=c-1,e.replaceChild(N(a),a);continue}}c&&kn(a,t||"PRE"===s)}else{if(d===F){if(f=a.data,h=!pt.test(f.charAt(0)),u=!pt.test(f.charAt(f.length-1)),t||!h&&!u)continue;if(h){for(jt.currentNode=a;(p=jt.previousPONode())&&(s=p.nodeName,!("IMG"===s||"#text"===s&&/\S/.test(p.data)));)if(!r(p)){p=null;break}f=f.replace(/^\s+/g,p?" ":"")}if(u){for(jt.currentNode=a;(p=jt.nextNode())&&!("IMG"===s||"#text"===s&&/\S/.test(p.data));)if(!r(p)){p=null;break}f=f.replace(/\s+$/g,p?" ":"")}if(f){a.data=f;continue}}e.removeChild(a),o-=1,i-=1}return e},Vt=function xn(e){for(var t,n=e.childNodes,o=n.length;o--;)t=n[o],t.nodeType!==w||i(t)?t.nodeType!==F||t.data||e.removeChild(t):(xn(t),r(t)&&!t.firstChild&&e.removeChild(t))},$t=function(e){return e.nodeType===w?"BR"===e.nodeName:pt.test(e.data)},Yt=function(e){for(var t,o=e.parentNode;r(o);)o=o.parentNode;return t=new n(o,W|z,$t),t.currentNode=e,!!t.nextNode()},Xt=function(e,t){var n,o,i,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=Yt(a[n]);for(;d--;)o=a[d],i=o.parentNode,i&&(s[d]?r(i)||y(i,t):v(o))},Jt=function(e){var t=e.clipboardData,n=this.getSelection(),o=this.createElement("div"),i=this._root,r=this;this.saveUndoState(n),at||et||!t?setTimeout(function(){try{r._ensureBottomLine()}catch(e){r.didError(e)}},0):(xt(n,i),o.appendChild(Tt(n,i)),t.setData("text/html",o.innerHTML),t.setData("text/plain",o.innerText||o.textContent),e.preventDefault()),this.setSelection(n)},en=function(e){var t,n,o,i,r=e.clipboardData,a=this.getSelection(),s=this.createElement("div"),d=this._root;if(!at&&!et&&r){if(a=a.cloneRange(),t=Bt(a,d),t===Lt(a,d))kt(a),xt(a,t),n=a.cloneContents();else for(xt(a,d),n=a.cloneContents(),o=a.commonAncestorContainer;o&&o!==d;)i=o.cloneNode(!1),i.appendChild(n),n=i,o=o.parentNode;s.appendChild(n),r.setData("text/html",s.innerHTML),r.setData("text/plain",s.innerText||s.textContent),e.preventDefault()}},tn=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(!at&&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&&n.getAsString(function(e){u.insertPlainText(e,!0)}))}if(i=a&&a.types,!at&&i&&(gt.call(i,"text/html")>-1||!ot&>.call(i,"text/plain")>-1&>.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,C=p.endContainer,N=p.endOffset,_=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(_),p.selectNodeContents(_),this.setSelection(p),setTimeout(function(){try{u._awaitingPaste=!1;for(var e,t,n="",o=_;_=o;)o=_.nextSibling,v(_),e=_.firstChild,e&&e===_.lastChild&&"DIV"===e.nodeName&&(_=e),n+=_.innerHTML;t=u._createRange(g,m,C,N),u.setSelection(t),n&&u.insertHTML(n,!0)}catch(i){u.didError(i)}},0)},nn=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()},on=[],rn=O.prototype;rn.setConfig=function(e){return e=A({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null},leafNodeNames:Ct,undo:{documentSizeThreshold:-1,undoLimit:-1}},e,!0),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},rn.createElement=function(e,t,n){return _(this._doc,e,t,n)},rn.createDefaultBlock=function(e){var t=this._config;return S(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},rn.didError=function(e){console.log(e)},rn.getDocument=function(){return this._doc},rn.getRoot=function(){return this._root},rn.modifyDocument=function(e){this._ignoreAllChanges=!0,this._mutation&&this._mutation.disconnect(),e(),this._ignoreAllChanges=!1,this._mutation&&this._mutation.observe(this._root,{childList:!0,attributes:!0,characterData:!0,subtree:!0})};var an={pathChange:1,select:1,input:1,undoStateChange:1};rn.fireEvent=function(e,t){var n,o,i,r=this._events[e];if(/^(?:focus|blur)/.test(e))if(n=p(this._root,this._doc.activeElement),"focus"===e){if(!n||this._isFocused)return this;this._isFocused=!0}else{if(n||!this._isFocused)return this;this._isFocused=!1}if(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(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},rn.destroy=function(){var e,t=on.length,n=this._events;for(e in n)this.removeEventListener(e);for(this._mutation&&this._mutation.disconnect();t--;)on[t]===this&&on.splice(t,1);this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0},rn.handleEvent=function(e){this.fireEvent(e.type,e)},rn.addEventListener=function(e,t){var n=this._events[e],o=this._root;return t?(n||(n=this._events[e]=[],an[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)},rn.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],an[e]||("selectionchange"===e&&(i=this._doc),i.removeEventListener(e,this,!0)))}return this},rn._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},rn.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,o=e.getBoundingClientRect();return o&&!o.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=Y,St(e,t),o=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),b(n,e)),o},rn._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return kt(n),this.setSelection(n),this},rn.moveCursorToStart=function(){return this._moveCursorTo(!0)},rn.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var sn=function(e){return e._win.getSelection()||null};rn.setSelection=function(e){if(e)if(this._lastSelection=e,this._isFocused)if(nt&&!this._restoreSelection)D.call(this),this.blur(),this.focus();else{et&&this._win.focus();var t=sn(this);t&&(t.removeAllRanges(),t.addRange(e))}else D.call(this);return this},rn.getSelection=function(){var e,t,n,o=sn(this),r=this._root;return o&&o.rangeCount&&(e=o.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&i(t)&&e.setStartBefore(t),n&&i(n)&&e.setEndBefore(n)),e&&p(r,e.commonAncestorContainer)?this._lastSelection=e:e=this._lastSelection,e||(e=this._createRange(r.firstChild,0)),e},rn.getSelectedText=function(){var e,t=this.getSelection(),o=new n(t.commonAncestorContainer,z|W,function(e){return bt(t,e,!0)}),i=t.startContainer,a=t.endContainer,s=o.currentNode=i,d="",l=!1;for(o.filter(s)||(s=o.nextNode());s;)s.nodeType===F?(e=s.data,e&&/\S/.test(e)&&(s===a&&(e=e.slice(0,t.endOffset)),s===i&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===s.nodeName||l&&!r(s))&&(d+="\n",l=!1),s=o.nextNode();return d},rn.getPath=function(){return this._path};var dn=function(e,t){for(var o,i,a,s=new n(e,z,function(){return!0},!1);i=s.nextNode();)for(;(a=i.data.indexOf(Y))>-1&&(!t||i.parentNode!==t);){if(1===i.length){do o=i.parentNode,o.removeChild(i),i=o,s.currentNode=o;while(r(i)&&!m(i));break}i.deleteData(a,1)}};rn._didAddZWS=function(){this._hasZWS=!0},rn._removeZWS=function(){this._hasZWS&&(dn(this._root),this._hasZWS=!1)},rn._updatePath=function(e,t){var n,o=e.startContainer,i=e.endContainer;(t||o!==this._lastAnchorNode||i!==this._lastFocusNode)&&(this._lastAnchorNode=o,this._lastFocusNode=i,n=o&&i?o===i?g(i,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},rn._updatePathOnEvent=function(){var e=this;e._willUpdatePath||(e._willUpdatePath=!0,setTimeout(function(){e._willUpdatePath=!1,e._updatePath(e.getSelection())},0))},rn.focus=function(){return this._root.focus(),dt&&this.fireEvent("focus"),this},rn.blur=function(){return this._root.blur(),dt&&this.fireEvent("blur"),this};var ln="squire-selection-start",cn="squire-selection-end";rn._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:ln,type:"hidden"}),o=this.createElement("INPUT",{id:cn,type:"hidden"});St(e,n),e.collapse(!1),St(e,o),n.compareDocumentPosition(o)&I&&(n.id=cn,o.id=ln,t=n,n=o,o=t),e.setStartAfter(n),e.setEndBefore(o)},rn._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+ln),o=t.querySelector("#"+cn);if(n&&o){var i=n.parentNode,r=o.parentNode,a=gt.call(i.childNodes,n),s=gt.call(r.childNodes,o);i===r&&(s-=1),v(n),v(o),e||(e=this._doc.createRange()),e.setStart(i,a),e.setEnd(r,s),b(i,e),i!==r&&b(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},rn._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},rn._docWasChanged=function(){if(!this._ignoreAllChanges){if(ft&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},rn._recordUndoState=function(e){if(!this._isInUndoState){var t,n=this._undoIndex+=1,o=this._undoStack,i=this._config.undo,r=i.documentSizeThreshold,a=i.undoLimit;n-1&&2*t.length>r&&a>-1&&n>a&&(o.splice(0,n-a),n=this._undoIndex=a,this._undoStackLength=a),o[n]=t,this._undoStackLength+=1,this._isInUndoState=!0}},rn.saveUndoState=function(e){return e===t&&(e=this.getSelection()),this._isInUndoState||(this._recordUndoState(e),this._getRangeAndRemoveBookmark(e)),this},rn.undo=function(){if(0!==this._undoIndex||!this._isInUndoState){this._recordUndoState(this.getSelection()),this._undoIndex-=1,this._setHTML(this._undoStack[this._undoIndex]);var e=this._getRangeAndRemoveBookmark();e&&this.setSelection(e),this._isInUndoState=!0,this.fireEvent("undoStateChange",{canUndo:0!==this._undoIndex,canRedo:!0}),this.fireEvent("input")}return this},rn.redo=function(){var e=this._undoIndex,t=this._undoStackLength;if(t>e+1&&this._isInUndoState){this._undoIndex+=1,this._setHTML(this._undoStack[this._undoIndex]);
+var n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:t>e+2}),this.fireEvent("input")}return this},rn.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(f(s,a,e,t))return!0;if(s.nodeType===F)return!1;i=new n(s,z,function(e){return bt(o,e,!0)},!1);for(var d=!1;r=i.nextNode();){if(!f(r,a,e,t))return!1;d=!0}return d},rn.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);4>a&&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},rn._addFormat=function(e,t,o){var i,a,s,d,l,c,h,u,p,g=this._root;if(o.collapsed){for(i=S(this.createElement(e,t),g),St(o,i),o.setStart(i.firstChild,i.firstChild.length),o.collapse(!0),p=i;r(p);)p=p.parentNode;dn(p,i)}else{if(a=new n(o.commonAncestorContainer,z|W,function(e){return(e.nodeType===F||"BR"===e.nodeName||"IMG"===e.nodeName)&&bt(o,e,!0)},!1),s=o.startContainer,l=o.startOffset,d=o.endContainer,c=o.endOffset,a.currentNode=s,a.filter(s)||(s=a.nextNode(),l=0),!s)return o;do h=a.currentNode,u=!f(h,g,e,t),u&&(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),C(h,i),i.appendChild(h));while(a.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},rn._removeFormat=function(e,t,n,o){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(ht?(i=a.createTextNode(Y),this._didAddZWS()):i=a.createTextNode(""),St(n,i));for(var s=n.commonAncestorContainer;r(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,h=n.endOffset,f=[],p=function(e,t){if(!bt(n,e,!1)){var o,i,r=e.nodeType===F;if(!bt(n,e,!0))return void("INPUT"===e.nodeName||r&&!e.data||f.push([t,e]));if(r)e===c&&h!==e.length&&f.push([t,e.splitText(h)]),e===d&&l&&(e.splitText(l),f.push([t,e]));else for(o=e.firstChild;o;o=i)i=o.nextSibling,p(o,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(o){return bt(n,o,!0)&&u(o,e,t)});return o||g.forEach(function(e){p(e,e)}),f.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1),b(s,n),n},rn.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),ft||this._docWasChanged(),this):this};var hn={DT:"DD",DD:"DT",LI:"LI"},un=function(e,t,n,o){var i=hn[t.nodeName],r=null,a=T(n,o,t.parentNode,e._root),s=e._config;return i||(i=s.blockTag,r=s.blockAttributes),u(a,i,r)||(t=_(a.ownerDocument,i,r),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(N(a)),a=t),a};rn.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var o=this._root,i=Bt(n,o),r=Lt(n,o);if(i&&r)do if(e(i)||i===r)break;while(i=c(i,o));return t&&(this.setSelection(n),this._updatePath(n,!0),ft||this._docWasChanged()),this},rn.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t);var n,o=this._root;return Rt(t,o),xt(t,o),n=yt(t,o,o),St(t,e.call(this,n)),t.endOffsett;t+=1){for(i=d[t],r=N(i),a=r.childNodes,o=a.length;o--;)s=a[o],C(s,N(s));y(r,this._root),C(i,r)}return e},_n=function(e){var t,n,o,i,r,a,d=e.querySelectorAll("LI"),l=this._config.tagAttributes,c=l.li;for(t=0,n=d.length;n>t;t+=1)o=d[t],s(o.firstChild)||(i=o.parentNode.nodeName,r=o.previousSibling,r&&(r=r.lastChild)&&r.nodeName===i||(a=l[i.toLowerCase()],C(o,this.createElement("LI",c,[r=this.createElement(i,a)]))),r.appendChild(o));return e},Sn=function(e){var t=this._root,n=e.querySelectorAll("LI");return Array.prototype.filter.call(n,function(e){return!s(e.firstChild)}).forEach(function(n){var o,i=n.parentNode,r=i.parentNode,a=n.firstChild,d=a;for(n.previousSibling&&(i=T(i,n,r,t));d&&(o=d.nextSibling,!s(d));)r.insertBefore(d,i),d=o;for("LI"===r.nodeName&&a.previousSibling&&T(r,a,r.parentNode,t);n!==e&&!n.childNodes.length;)i=n.parentNode,i.removeChild(n),n=i},this),y(e,t),e};rn._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},rn.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},rn._getHTML=function(){return this._root.innerHTML},rn._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do S(n,t);while(n=c(n,t));this._ignoreChange=!0},rn.getHTML=function(e){var t,n,o,i,r,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),ct)for(t=this._root,n=t;n=c(n,t);)n.textContent||n.querySelector("BR")||(o=this.createElement("BR"),n.appendChild(o),s.push(o));if(i=this._getHTML().replace(/\u200B/g,""),ct)for(r=s.length;r--;)v(s[r]);return a&&this._getRangeAndRemoveBookmark(a),i},rn.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),o=this.createElement("DIV"),i=this._root;o.innerHTML=e,n.appendChild(N(o)),Qt(n),Xt(n,i),y(n,i);for(var r=n;r=c(r,i);)S(r,i);for(this._ignoreChange=!0;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(i,i),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var a=this._getRangeAndRemoveBookmark()||this._createRange(i.firstChild,0);return this.saveUndoState(a),this._lastSelection=a,D.call(this),this._updatePath(a,!0),this},rn.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),r(e))St(t,e),t.setStartAfter(e);else{for(var n,o,i=this._root,a=Bt(t,i)||i;a!==i&&!a.nextSibling;)a=a.parentNode;a!==i&&(n=a.parentNode,o=T(n,a.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),kt(t)}return this.focus(),this.setSelection(t),this._updatePath(t),ft||this._docWasChanged(),this},rn.insertImage=function(e,t){var n=this.createElement("IMG",A({src:e},t,!0));return this.insertElement(n),n};var yn=/\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,Tn=function(e,t,o){for(var i,r,a,s,d,l,c,h=e.ownerDocument,u=new n(e,z,function(e){return!f(e,t,"A")},!1),p=o._config.tagAttributes.a;i=u.nextNode();)for(r=i.data,a=i.parentNode;s=yn.exec(r);)d=s.index,l=d+s[0].length,d&&(c=h.createTextNode(r.slice(0,d)),a.insertBefore(c,i)),c=o.createElement("A",A({href:s[1]?/^(?:ht|f)tps?:/.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[2]},p,!1)),c.textContent=r.slice(d,l),a.insertBefore(c,i),i.data=r=r.slice(l)};rn.insertHTML=function(e,t){var n,o,i,r,a,s,d,l=this.getSelection(),h=this._doc;"undefined"!=typeof DOMPurify&&DOMPurify.isSupported?(r=DOMPurify.sanitize(e,{WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0}),r=h.importNode(r,!0)):(t&&(n=e.indexOf(""),o=e.lastIndexOf(""),n>-1&&o>-1&&(e=e.slice(n+20,o))),i=this.createElement("DIV"),i.innerHTML=e,r=h.createDocumentFragment(),r.appendChild(N(i))),this.saveUndoState(l);try{for(a=this._root,s=r,d={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1},Tn(r,r,this),Qt(r),Xt(r,null),Vt(r),r.normalize();s=c(s,r);)S(s,null);t&&this.fireEvent("willPaste",d),d.defaultPrevented||(Et(l,d.fragment,a),ft||this._docWasChanged(),l.collapse(!1),this._ensureBottomLine()),this.setSelection(l),this._updatePath(l,!0),t&&this.focus()}catch(u){this.didError(u)}return this};var En=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};rn.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+'="'+En(l[n])+'"';for(h+=">",o=0,i=a.length;i>o;o+=1)r=a[o],r=En(r).replace(/ (?= )/g," "),o&&i>o+1&&(r=h+(r||"
")+c),a[o]=r;return this.insertHTML(a.join(""),t)};var bn=function(e,t,n){return function(){return this[e](t,n),this.focus()}};rn.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},rn.bold=bn("changeFormat",{tag:"B"}),rn.italic=bn("changeFormat",{tag:"I"}),rn.underline=bn("changeFormat",{tag:"U"}),rn.strikethrough=bn("changeFormat",{tag:"S"}),rn.subscript=bn("changeFormat",{tag:"SUB"},{tag:"SUP"}),rn.superscript=bn("changeFormat",{tag:"SUP"},{tag:"SUB"}),rn.removeBold=bn("changeFormat",null,{tag:"B"}),rn.removeItalic=bn("changeFormat",null,{tag:"I"}),rn.removeUnderline=bn("changeFormat",null,{tag:"U"}),rn.removeStrikethrough=bn("changeFormat",null,{tag:"S"}),rn.removeSubscript=bn("changeFormat",null,{tag:"SUB"}),rn.removeSuperscript=bn("changeFormat",null,{tag:"SUP"}),rn.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var o=e.indexOf(":")+1;if(o)for(;"/"===e[o];)o+=1;St(n,this._doc.createTextNode(e.slice(o)))}return t=A(A({href:e},t,!0),this._config.tagAttributes.a,!1),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},rn.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},rn.setFontFace=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},rn.setFontSize=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}}:null,{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},rn.setTextColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}}:null,{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},rn.setHighlightColour=function(e){return this.changeFormat(e?{tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}}:e,{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},rn.setTextAlignment=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/align/.test(e)}).join(" ")+" align-"+e).trim(),t.style.textAlign=e},!0),this.focus()},rn.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},rn.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=this._root,n=e.commonAncestorContainer;n&&!a(n);)n=n.parentNode;if(n||(Rt(e,t),n=t),n.nodeType===F)return this;this.saveUndoState(e),xt(e,n);for(var o,i,r=n.ownerDocument,s=e.startContainer,d=e.startOffset,l=e.endContainer,c=e.endOffset,h=r.createDocumentFragment(),u=r.createDocumentFragment(),f=T(l,c,n,t),p=T(s,d,n,t);p!==f;)o=p.nextSibling,h.appendChild(p),p=o;return P(this,h,u),u.normalize(),p=u.firstChild,o=u.lastChild,i=n.childNodes,p?(n.insertBefore(u,f),d=gt.call(i,p),c=gt.call(i,o)+1):(d=gt.call(i,f),c=d),e.setStart(n,d),e.setEnd(n,c),b(n,e),kt(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},rn.increaseQuoteLevel=bn("modifyBlocks",fn),rn.decreaseQuoteLevel=bn("modifyBlocks",pn),rn.makeUnorderedList=bn("modifyBlocks",vn),rn.makeOrderedList=bn("modifyBlocks",Cn),rn.removeList=bn("modifyBlocks",Nn),rn.increaseListLevel=bn("modifyBlocks",_n),rn.decreaseListLevel=bn("modifyBlocks",Sn),O.getNodeBefore=Nt,O.getNodeAfter=_t,O.insertNodeInRange=St,O.extractContentsOfRange=yt,O.deleteContentsOfRange=Tt,O.insertTreeFragmentIntoRange=Et,O.isNodeContainedInRange=bt,O.moveRangeBoundariesDownTree=kt,O.moveRangeBoundariesUpTree=xt,O.getStartBlockOfRange=Bt,O.getEndBlockOfRange=Lt,O.contentWalker=At,O.rangeDoesStartAtBlockBoundary=Ot,O.rangeDoesEndAtBlockBoundary=Dt,O.expandRangeToBlockBoundaries=Rt,O.onPaste=tn,O.addLinks=Tn,O.splitBlock=un,O.startSelectionId=ln,O.endSelectionId=cn,"object"==typeof exports?module.exports=O:"function"==typeof define&&define.amd?define(function(){return O}):(X.Squire=O,top!==X&&"true"===e.documentElement.getAttribute("data-squireinit")&&(X.editor=new O(e),X.onEditorLoad&&(X.onEditorLoad(X.editor),X.onEditorLoad=null)))}(document);
\ No newline at end of file