!function(e,n){"function"==typeof define&&define.amd?define(["./rangy-core"],e):"undefined"!=typeof module&&"object"==typeof exports?module.exports=e(require("rangy")):e(n.rangy)}(function(e){return e.createModule("Serializer",["WrappedSelection"],function(a,d){var e,n="undefined",t=a.util,o=(typeof encodeURIComponent!=n&&typeof decodeURIComponent!=n||d.fail("encodeURIComponent and/or decodeURIComponent method is missing"),e=null,function(e){for(var n=function(e){for(var n,t=[],o=0,r=e.length;o<r;++o)(n=e.charCodeAt(o))<128?t.push(n):n<2048?t.push(n>>6|192,63&n|128):t.push(n>>12|224,n>>6&63|128,63&n|128);return t}(e),t=-1,o=c(),r=0,i=n.length;r<i;++r)t=t>>>8^o[255&(t^n[r])];return(-1^t)>>>0});function c(){return e=e||function(){for(var e,n,t=[],o=0;o<256;++o){for(n=o,e=8;e--;)1==(1&n)?n=n>>>1^3988292384:n>>>=1;t[o]=n>>>0}return t}()}var u=a.dom;function s(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;")}function l(e,n){n=n||[];var t=e.nodeType,o=e.childNodes,r=o.length,i=[t,e.nodeName,r].join(":"),c="",a="";switch(t){case 3:c=s(e.nodeValue);break;case 8:c="\x3c!--"+s(e.nodeValue)+"--\x3e";break;default:c="<"+i+">",a="</>"}c&&n.push(c);for(var d=0;d<r;++d)l(o[d],n);return a&&n.push(a),n}function i(e){e=l(e).join("");return o(e).toString(16)}function r(e,n,t){var o=[],r=e;for(t=t||u.getDocument(e).documentElement;r&&r!=t;)o.push(u.getNodeIndex(r,!0)),r=r.parentNode;return o.join("/")+":"+n}function f(e,n,t){n=n||(t||document).documentElement;for(var o,t=e.split(":"),r=n,i=t[0]?t[0].split("/"):[],c=i.length;c--;){if(!((o=parseInt(i[c],10))<r.childNodes.length))throw d.createError("deserializePosition() failed: node "+u.inspectNode(r)+" has no child with index "+o+", "+c);r=r.childNodes[o]}return new u.DomPosition(r,parseInt(t[1],10))}function m(e,n,t){if(t=t||a.DomRange.getRangeDocument(e).documentElement,!u.isOrIsAncestorOf(t,e.commonAncestorContainer))throw d.createError("serializeRange(): range "+e.inspect()+" is not wholly contained within specified root node "+u.inspectNode(t));e=r(e.startContainer,e.startOffset,t)+","+r(e.endContainer,e.endOffset,t);return n||(e+="{"+i(t)+"}"),e}var p=/^([^,]+),([^,\{]+)(\{([^}]+)\})?$/;function g(e,n,t){n?t=t||u.getDocument(n):n=(t=t||document).documentElement;var e=p.exec(e),o=e[4];if(o){var r=i(n);if(o!==r)throw d.createError("deserializeRange(): checksums of serialized range root node ("+o+") and target root node ("+r+") do not match")}o=f(e[1],n,t),r=f(e[2],n,t),e=a.createRange(t);return e.setStartAndEnd(o.node,o.offset,r.node,r.offset),e}function h(e,n,t){n=n||(t||document).documentElement;t=p.exec(e)[3];return!t||t===i(n)}function v(e,n,t){for(var o=(e=a.getSelection(e)).getAllRanges(),r=[],i=0,c=o.length;i<c;++i)r[i]=m(o[i],n,t);return r.join("|")}function w(e,n,t){n?t=t||u.getWindow(n):n=(t=t||window).document.documentElement;for(var o=e.split("|"),e=a.getSelection(t),r=[],i=0,c=o.length;i<c;++i)r[i]=g(o[i],n,t.document);return e.setRanges(r),e}var R="rangySerializedSelection";t.extend(a,{serializePosition:r,deserializePosition:f,serializeRange:m,deserializeRange:g,canDeserializeRange:h,serializeSelection:v,deserializeSelection:w,canDeserializeSelection:function(e,n,t){n?o=t?t.document:u.getDocument(n):n=(t=t||window).document.documentElement;for(var o,r=e.split("|"),i=0,c=r.length;i<c;++i)if(!h(r[i],n,o))return!1;return!0},restoreSelectionFromCookie:function(e){var n=function(e){for(var n,t=e.split(/[;,]/),o=0,r=t.length;o<r;++o)if((n=t[o].split("="))[0].replace(/^\s+/,"")==R&&(n=n[1]))return decodeURIComponent(n.replace(/\s+$/,""));return null}((e=e||window).document.cookie);n&&w(n,e.doc)},saveSelectionCookie:function(e,n){e=e||window;var t=(n="object"==typeof n?n:{}).expires?";expires="+n.expires.toUTCString():"",o=n.path?";path="+n.path:"",r=n.domain?";domain="+n.domain:"",n=n.secure?";secure":"",i=v(a.getSelection(e));e.document.cookie=encodeURIComponent(R)+"="+encodeURIComponent(i)+t+o+r+n},getElementChecksum:i,nodeToInfoString:l}),t.crc32=o}),e},this);